Ejemplo n.º 1
0
        public async Task UploadImageAsync(IFormFile image, string userId)
        {
            byte[] imageByte;
            string path = string.Empty;

            using (var memoryStream = new MemoryStream())
            {
                await image.CopyToAsync(memoryStream);

                imageByte = memoryStream.ToArray();
            }

            using (var destinationSteam = new MemoryStream(imageByte))
            {
                var uploadParams = new ImageUploadParams()
                {
                    File = new FileDescription(image.Name, destinationSteam)
                };
                var uploadResult = await cloudinary.UploadAsync(uploadParams);

                path = uploadResult.Uri.AbsoluteUri;
            }

            var photo = new Photo
            {
                Url    = path,
                UserId = userId
            };

            this.db.Photos.Add(photo);
            this.db.SaveChanges();
        }
        public static async Task <string> UploadImage(Context context, Uri imageUri, string publicId, int size)
        {
            var account =
                new CloudinaryDotNet.Account(CloudName, ApiKey, ApiSecret);

            var cloudinary = new CloudinaryDotNet.Cloudinary(account);

            var uploadParams = new CloudinaryDotNet.Actions.ImageUploadParams
            {
                File     = new CloudinaryDotNet.Actions.FileDescription(FilePathUtilities.GetAbsoluteFilePath(context, GetImageUri(context, ResizeImage(context, imageUri, size)))),
                PublicId = publicId
            };

            var uploadResult = await cloudinary.UploadAsync(uploadParams);

            return(uploadResult.Uri.OriginalString);
        }