Exemple #1
0
        private void AssignImages(bsi_posts post, string parentID)
        {
            //Upload associated images
            string index     = "";
            int    count     = 1;
            string imagePath = @"P:/products/" + post.bsi_posting.brand + @"/" + post.sku + ".jpg";

            while (File.Exists(imagePath))
            {
                catalogProductAttributeMediaCreateEntity media = UploadProductImage(imagePath, count, post.sku + index);
                _proxy.catalogProductAttributeMediaCreate(_sessionID, parentID.ToString(), media, null, "product ID");

                count++;
                index     = "-" + count.ToString();
                imagePath = @"P:/products/" + post.bsi_posting.brand + @"/" + post.sku + index + ".jpg";
            }
        }
Exemple #2
0
        private catalogProductAttributeMediaCreateEntity UploadProductImage(string path, int count, string label)
        {
            var imageStream = new MemoryStream();

            using (var i = Image.FromFile(path))
            {
                i.Save(imageStream, ImageFormat.Jpeg);
            }
            byte[] encbuff = imageStream.ToArray();

            string enc = Convert.ToBase64String(encbuff, 0, encbuff.Length);


            var imageEntity = new catalogProductImageFileEntity();

            imageEntity.content = enc;
            imageEntity.mime    = "image/jpeg";

            imageStream.Close();

            string[] types = null;

            if (count == 1)
            {
                types = new string[] { "image", "small_image", "thumbnail" }
            }
            ;
            else
            {
                types = new string[] { "0", "0", "0" }
            };

            //"image", "small_image", "thumbnail"

            var entityP = new catalogProductAttributeMediaCreateEntity();

            entityP.label    = label;
            entityP.file     = imageEntity;
            entityP.types    = types;
            entityP.position = "0";
            entityP.exclude  = "0";

            return(entityP);
        }