Exemple #1
0
        public ItemImage UploadImage()
        {
            var userId  = User.Identifier();
            var request = HttpContext.Current.Request;

            var image = new ItemImageInput()
            {
                UserIdentifier = userId,
                ItemIdentifier = Guid.Parse(request.Form["Identifier"]),
            };

            if (request.Files.Count > 0)
            {
                //we are uploading the old way
                var file = request.Files[0];
                image.Contents = new byte[file.ContentLength];
                file.InputStream.Read(image.Contents, 0, file.ContentLength);
                image.ContentType = file.ContentType;
                image.FileName    = file.FileName;
            }
            else if (request.ContentLength > 0)
            {
                // Using FileAPI the content is in Request.InputStream!!!!
                image.Contents = new byte[request.ContentLength];
                request.InputStream.Read(image.Contents, 0, request.ContentLength);
                image.FileName    = request.Headers["X-File-Name"];
                image.ContentType = request.Headers["X-File-Type"];
            }

            image.FileSize = image.Contents != null ? image.Contents.Length : 0;

            return(this.imageCore.Save(image));
        }
Exemple #2
0
        public void NewItemImage(ItemImageInput item)
        {
            var activity = new Activity()
            {
                Type                = Reference.ItemImage,
                Text                = string.Format("added a photo to an item"),
                UserIdentifier      = item.UserIdentifier,
                ReferenceIdentifier = item.Identifier,
            };

            this.Save(activity);
        }
Exemple #3
0
        /// <summary>
        /// Save Image
        /// </summary>
        /// <param name="image">Image</param>
        /// <returns>Item Image</returns>
        public ItemImage Save(ItemImageInput image)
        {
            var id          = Guid.NewGuid();
            var virtualPath = string.Format("item/{0}_{1}.jpg", id, "{0}");
            var sproc       = new GoodsSaveItemImage()
            {
                Identifier     = id,
                ContentType    = image.ContentType,
                FileName       = image.FileName,
                FileSize       = image.FileSize,
                ItemIdentifier = image.ItemIdentifier,
                UserIdentifier = image.UserIdentifier,
                Path           = string.Format("/user/{0}", virtualPath),
            };

            var storedImage = sproc.CallObject <ItemImageInput>();

            var container = new BinaryContainer("user");

            container.Save(string.Format(virtualPath, OriginalName), image.Contents, image.ContentType);

            var thumbnail = this.Thumbnail(image.Contents, ImageFormat.Jpeg);

            var thumbnailPath = string.Format(virtualPath, ImageCore.ThumbnailName);

            container.Save(thumbnailPath, thumbnail, contentType);

            var large = this.Large(image.Contents, ImageFormat.Jpeg);

            var largePath = string.Format(virtualPath, ImageCore.LargeName);

            container.Save(largePath, large, contentType);

            var activity = new ActivityCore();

            activity.NewItemImage(storedImage);

            return(new ItemImage()
            {
                VirtualPathFormat = string.Format("/user/{0}", thumbnailPath),
            });
        }
Exemple #4
0
        public ItemImage SaveImagebyUrl(PublicItemImage image)
        {
            if (null == image)
            {
                throw new ArgumentNullException("image");
            }

            if (Guid.Empty == image.ItemIdentifier)
            {
                throw new ArgumentException("Identifer");
            }

            var userId = User.Identifier();

            var itemImage = new ItemImageInput()
            {
                UserIdentifier = userId,
                ItemIdentifier = image.ItemIdentifier,
                FileName       = image.Url,
            };

            using (var file = imageCore.Download(image.Url))
            {
                itemImage.ContentType = file.ContentType;
                using (var response = file.GetResponseStream())
                {
                    using (var ms = new MemoryStream())
                    {
                        response.CopyTo(ms);
                        itemImage.Contents = ms.ToArray();
                    }
                }
            }

            return(this.imageCore.Save(itemImage));
        }