public void TestGetTransform() { // should allow getting transformation metadata Transformation t = new Transformation().Crop("scale").Width(2.0); ImageUploadParams uploadParams = new ImageUploadParams() { File = new FileDescription(m_testImagePath), EagerTransforms = new List <Transformation>() { t }, Tags = "transformation" }; m_cloudinary.Upload(uploadParams); GetTransformResult result = m_cloudinary.GetTransform("c_scale,w_2"); Assert.IsNotNull(result); Assert.AreEqual(t.Generate(), new Transformation(result.Info[0]).Generate()); }
public async Task <PhotoUploadResult> AddPhoto(IFormFile file) { if (file.Length > 0) { await using var stream = file.OpenReadStream(); var uploadParams = new ImageUploadParams { File = new FileDescription(file.FileName, stream), Transformation = new Transformation().Height(500).Width(500).Crop("fill") }; var uploadResult = await _cloudinary.UploadAsync(uploadParams); return(new PhotoUploadResult { PublicId = uploadResult.PublicId, Url = uploadResult.SecureUrl.ToString() }); } return(null); }
public async Task <string> UploadAsync(Cloudinary cloudinary, IFormFile file) { byte[] destinationImage; using (var memoryStream = new MemoryStream()) { await file.CopyToAsync(memoryStream); destinationImage = memoryStream.ToArray(); } using (var destinationStream = new MemoryStream(destinationImage)) { var uploadParams = new ImageUploadParams() { File = new FileDescription(file.FileName, destinationStream), }; var result = await cloudinary.UploadAsync(uploadParams); return(result.Uri.AbsoluteUri); } }
public void TestTagReplace() { ImageUploadParams uploadParams = new ImageUploadParams() { File = new FileDescription(m_testImagePath), Tags = "test++++++tag" }; ImageUploadResult uploadResult = m_cloudinary.Upload(uploadParams); TagParams tagParams = new TagParams() { Command = TagCommand.Replace, Tag = "another-tag-test" }; tagParams.PublicIds.Add(uploadResult.PublicId); TagResult tagResult = m_cloudinary.Tag(tagParams); Assert.AreEqual(1, tagResult.PublicIds.Length); Assert.AreEqual(uploadResult.PublicId, tagResult.PublicIds[0]); }
public async Task <ImageUploadResult> AddPhotoAsync(IFormFile file) { ImageUploadResult uploadResult = new ImageUploadResult(); if (file.Length > 0) { Stream stream = file.OpenReadStream(); ImageUploadParams uploadParams = new ImageUploadParams() { File = new FileDescription(file.FileName, stream), Transformation = new Transformation() .Height(500) .Width(500) .Crop("fill") .Gravity("face") }; uploadResult = await _cloudinary.UploadAsync(uploadParams); return(uploadResult); } return(uploadResult); }
public void TestUploadLocalImageAsync() { var uploadParams = new ImageUploadParams() { File = new FileDescription(m_testImagePath) }; var uploadResult = m_cloudinary.UploadAsync(uploadParams).Result; Assert.AreEqual(1920, uploadResult.Width); Assert.AreEqual(1200, uploadResult.Height); Assert.AreEqual("jpg", uploadResult.Format); var checkParams = new SortedDictionary <string, object>(); checkParams.Add("public_id", uploadResult.PublicId); checkParams.Add("version", uploadResult.Version); var api = new Api(m_account); string expectedSign = api.SignParameters(checkParams); Assert.AreEqual(expectedSign, uploadResult.Signature); }
public async Task <string> UploadImageAsync(string imagePath, Stream imageStream) //+ public_id { try { var uploadParams = new ImageUploadParams() { File = new FileDescription(imagePath, imageStream) //PublicId = "sample_id" по которому будет уже реализована загрузка из сервера картинок, можно организовывать в папки: user/public_id }; var uploadResult = await cloudinary.UploadAsync(uploadParams); return(uploadResult.Url.AbsoluteUri); //Log "upload successfully" } catch (NullReferenceException e) { Console.WriteLine($"ImageManagment Service. NULL REF in upload async. {e.Message}"); return(null); //Log error occured e.Message } }
public ImageUploadResult UploadPhoto(PhotoForCreationDto photoForCreationDto) { var file = photoForCreationDto.File; var uploadResult = new ImageUploadResult(); if (file.Length > 0) { using (var stream = file.OpenReadStream()) { var uploadParams = new ImageUploadParams() { File = new FileDescription(file.Name, stream), Transformation = new Transformation() .Width(500).Height(500).Crop("fill").Gravity("face") }; uploadResult = _cloudinary.Upload(uploadParams); } } return(uploadResult); }
public void TestGetTransformAsync() { // should allow getting transformation metadata var uploadParams = new ImageUploadParams() { File = new FileDescription(m_testImagePath), EagerTransforms = new List <Transformation>() { m_resizeTransformation }, Tags = m_apiTag }; var uploadResult = m_cloudinary.UploadAsync(uploadParams).Result; var result = m_cloudinary.GetTransformAsync(new GetTransformParams { Transformation = m_resizeTransformationAsString }).Result; Assert.IsNotNull(result); }
public void TestTagAddAsync() { ImageUploadParams uploadParams = new ImageUploadParams() { File = new FileDescription(m_testImagePath), Tags = m_apiTag }; ImageUploadResult uploadResult = m_cloudinary.UploadAsync(uploadParams).Result; TagParams tagParams = new TagParams() { Command = TagCommand.Add, Tag = "SomeTagAsync" }; tagParams.PublicIds.Add(uploadResult.PublicId); TagResult tagResult = m_cloudinary.TagAsync(tagParams).Result; Assert.AreEqual(1, tagResult.PublicIds.Length); Assert.AreEqual(uploadResult.PublicId, tagResult.PublicIds[0]); }
public async Task <string> UploadPictureAsync(IFormFile pictureFile) { byte[] destinationImage; using (var memoryStream = new MemoryStream()) { await pictureFile.CopyToAsync(memoryStream); destinationImage = memoryStream.ToArray(); } UploadResult uploadResult = null; using (var destitanionStream = new MemoryStream(destinationImage)) { var uploadParams = new ImageUploadParams() { File = new FileDescription(pictureFile.FileName, destitanionStream), }; uploadResult = await this.cloudinary.UploadAsync(uploadParams); } return(uploadResult?.SecureUri.AbsoluteUri); }
private string UploadImg(string picPublicId) { byte[] imageBytes = Convert.FromBase64String(hdnImage.Value); MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length); Account account = new Account("dlyvxs7of", "634626974285569", "FtB_0jhcmFypFS7QTwCBKcPRGzE"); Cloudinary cloudinary = new Cloudinary(account); if (!string.IsNullOrEmpty(picPublicId)) { cloudinary.DeleteResources(new string[] { picPublicId }); } ImageUploadParams uploadParams = new ImageUploadParams() { File = new FileDescription("file", ms), }; ImageUploadResult result = cloudinary.Upload(uploadParams); return(result.PublicId); }
private async Task <ImageUploadResult> Upload(IFormFile file) { byte[] uploadFile; ImageUploadResult result; await using (var memoryStream = new System.IO.MemoryStream()) { await file.CopyToAsync(memoryStream); uploadFile = memoryStream.ToArray(); } await using (var uploadImageStream = new System.IO.MemoryStream(uploadFile)) { var uploadParams = new ImageUploadParams() { File = new FileDescription(file.FileName, uploadImageStream), }; result = await this.cloudinary.UploadAsync(uploadParams); } return(result); }
public void InitSearchTests() { m_searchTag = GetMethodTag(); m_expressionTag = $"tags:{m_searchTag}"; m_publicIdsSorted = new string[RESOURCES_COUNT]; for (var i = 0; i < RESOURCES_COUNT; i++) { string publicId = GetUniquePublicId(); var uploadParams = new ImageUploadParams() { PublicId = publicId, Tags = $"{m_searchTag},{m_apiTag}", File = new FileDescription(m_testImagePath) }; m_publicIdsSorted[i] = publicId; m_cloudinary.Upload(uploadParams); } Array.Sort(m_publicIdsSorted); m_expressionPublicId = $"public_id: {m_publicIdsSorted[0]}"; Thread.Sleep(INDEXING_WAIT_TIME); }
private ImagenEntity UploadingToCloudinary(CreacionImagenRequest request) { var file = request.Imagen; var uploadResult = new ImageUploadResult(); if (file.Length > 0) { using (var stream = file.OpenReadStream()) { var uploadParams = new ImageUploadParams() { File = new FileDescription(file.Name, stream), Transformation = new Transformation().Width(500).Height(500).Crop("fill").Gravity("face") }; uploadResult = _cloudinary.Upload(uploadParams); } } var imagenEntity = _mapper.Map <ImagenEntity>(request); imagenEntity.ImagenUrl = uploadResult.Uri.ToString(); imagenEntity.IdPublico = uploadResult.PublicId; return(imagenEntity); }
public string UpdateImageAndGetUrl(PaintingUpdateDTO image) { Account account = new Account( "paintingproject", //cloud name "373497354299735", //api key "6rt6J94a-ZylEscK5hZf5jLMyhM" //api secret ); var uploadParams = new ImageUploadParams() { File = new FileDescription(image.Image.FileName, image.Image.OpenReadStream()) }; var cloudinary = new Cloudinary(account); var uploadResult = cloudinary.Upload(uploadParams); var id = uploadResult.JsonObj; var data = JsonConvert.DeserializeObject <RawUploadResult>(id.ToString()); var result = data.SecureUri.ToString(); return(result); throw new NotImplementedException(); }
public async static Task <string> UploadImageToCloudinary(string filePath) { if (string.IsNullOrWhiteSpace(filePath)) { return(null); } if (!File.Exists(filePath)) { throw new Exception($"File not found at path: {filePath}"); } var uploadParams = new ImageUploadParams() { File = new FileDescription("ScoresPortalImg", filePath), Folder = "ScoresPortal", Phash = true }; var uploadResult = await Task.Run <ImageUploadResult>(() => App.CloudinaryInstance.Upload(uploadParams)); //var a =UploadResult.Phash.; return(uploadResult.SecureUri.AbsoluteUri); }
public void TestPublishByTag() { var publishTag = GetMethodTag(); var uploadParams = new ImageUploadParams { File = new FileDescription(m_testImagePath), Tags = $"{publishTag},{m_apiTag}", PublicId = GetUniquePublicId(), Overwrite = true, Type = STORAGE_TYPE_PRIVATE }; m_cloudinary.Upload(uploadParams); var publishResult = m_cloudinary.PublishResourceByTag(publishTag, new PublishResourceParams() { ResourceType = ResourceType.Image, }); Assert.NotNull(publishResult.Published); Assert.AreEqual(1, publishResult.Published.Count); }
public async Task <string> UploadImageAsync(IFormFile formFile) { if (formFile == null) { return(null); } using var stream = new MemoryStream(); await formFile.CopyToAsync(stream); var imageArray = stream.ToArray(); using var imageStream = new MemoryStream(imageArray); var uploadParams = new ImageUploadParams() { File = new FileDescription(formFile.Name, imageStream), }; var uploadResult = await _cloudinary.UploadAsync(uploadParams); return(uploadResult.PublicId); }
public async Task <string> UploadFile(byte[] destinationData, string filename) { ImageUploadResult uploadResult = null; using (var ms = new MemoryStream(destinationData)) { ImageUploadParams uploadParams = new ImageUploadParams { Folder = "coctails", File = new FileDescription(filename, ms), Transformation = new Transformation().Height(700).Width(700), }; uploadResult = _cloudinary.Upload(uploadParams); if (uploadResult.StatusCode == HttpStatusCode.OK) { return(uploadResult.Url.ToString()); } else { return(null); } } }
public async Task <ImageUploadResult> CategoryImagesUpload(IFormFile file) { try { Account account = new Account(_cloudinaryConfig.Cloud, _cloudinaryConfig.ApiKey, _cloudinaryConfig.ApiSecret); Cloudinary cloudinary = new Cloudinary(account); // var path = Path.Combine(Directory.GetCurrentDirectory(), "TempFileUpload", file.FileName); var path = Path.Combine(_hostingEnvironment.WebRootPath, file.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(stream); } //Uploads the Course Images to cloudinary var uploadParams = new ImageUploadParams() { File = new FileDescription(path), Transformation = new Transformation().Height(500).Width(500).Crop("scale"), PublicId = "Softlearn/course_category_Images/" + file.FileName + "", }; var uploadResult = cloudinary.Upload(uploadParams); //deletes the file from the "TempFileUplaod" directory if the status of upload result is okay if (uploadResult.StatusCode == System.Net.HttpStatusCode.OK) { System.IO.File.Delete(path); } return(uploadResult); } catch (Exception ex) { throw ex; } }
public void TestListResourcesByPublicIds() { var publicId1 = GetUniquePublicId(); var publicId2 = GetUniquePublicId(); var context = new StringDictionary("key=value", "key2=value2"); // should allow listing resources by public ids var uploadParams = new ImageUploadParams() { File = new FileDescription(m_testImagePath), PublicId = publicId1, Context = context, Tags = m_apiTag }; m_cloudinary.Upload(uploadParams); uploadParams = new ImageUploadParams() { File = new FileDescription(m_testImagePath), PublicId = publicId2, Context = context, Tags = m_apiTag }; m_cloudinary.Upload(uploadParams); List <string> publicIds = new List <string>() { publicId1, publicId2 }; var result = m_cloudinary.ListResourceByPublicIds(publicIds, true, true, true); Assert.NotNull(result); Assert.AreEqual(2, result.Resources.Length, "expected to find {0} but got {1}", new Object[] { publicIds.Aggregate((current, next) => current + ", " + next), result.Resources.Select(r => r.PublicId).Aggregate((current, next) => current + ", " + next) }); Assert.True(result.Resources.Where(r => r.Context != null).Count() == 2); }
public void TestAddContext() { var publicId = GetUniquePublicId(); var uploadParams = new ImageUploadParams() { File = new FileDescription(m_testImagePath), PublicId = publicId, Overwrite = true, Type = STORAGE_TYPE_UPLOAD, Tags = m_apiTag }; m_cloudinary.Upload(uploadParams); List <string> pIds = new List <string> { publicId }; ContextResult contextResult = m_cloudinary.Context(new ContextParams() { Command = ContextCommand.Add, PublicIds = pIds, Type = STORAGE_TYPE_UPLOAD, Context = "TestContext", ResourceType = ResourceType.Image }); Assert.True(contextResult.PublicIds.Length > 0); m_cloudinary.GetResource(new GetResourceParams(pIds[0]) { PublicId = pIds[0], Type = STORAGE_TYPE_UPLOAD, ResourceType = ResourceType.Image }); }
public async Task <IActionResult> AddPhotoForUser(long userId, [FromForm] PhotoForCreationDTO photoForCreationDTO) { if (userId != long.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(StatusCode(StatusCodes.Status401Unauthorized)); } var user = await _datingRepository.GetUser(userId); var file = photoForCreationDTO.File; var uploadResult = new ImageUploadResult(); if (file.Length > 0) { using var stream = file.OpenReadStream(); var uploadParams = new ImageUploadParams() { File = new FileDescription(file.Name, stream), Transformation = new Transformation().Width(500).Height(500).Crop("fill").Gravity("face") }; uploadResult = await _cloudinary.UploadAsync(uploadParams); } photoForCreationDTO.Url = uploadResult.Uri.ToString(); photoForCreationDTO.PublicId = uploadResult.PublicId; var photo = _mapper.Map <Photo>(photoForCreationDTO); photo.IsProfilePic = !user.Photos.Any(x => x.IsProfilePic); user.Photos.Add(photo); if (await _datingRepository.SaveAll()) { var photoToReturn = _mapper.Map <PhotoForReturnDTO>(photo); return(CreatedAtRoute(nameof(GetPhoto), new { userId, id = photo.Id }, photoToReturn)); } return(StatusCode(StatusCodes.Status400BadRequest, "Could not add the photo")); }
public async Task UploadAsync(IFormFile file, string id) { var currentImage = this.imageRepository.All().FirstOrDefault(c => c.ChannelId == id); if (currentImage != null) { this.cloudinary.DeleteResources(currentImage.CloudinaryPublicId); this.imageRepository.HardDelete(currentImage); await this.imageRepository.SaveChangesAsync(); } byte[] destinationImage; ImageUploadResult result; using (var memoryStream = new MemoryStream()) { await file.CopyToAsync(memoryStream); destinationImage = memoryStream.ToArray(); } using (var destinationStream = new MemoryStream(destinationImage)) { var uploadParams = new ImageUploadParams() { File = new FileDescription(file.FileName, destinationStream), }; result = await this.cloudinary.UploadAsync(uploadParams); } var imageUrl = result.Uri.AbsoluteUri.Replace("http://res.cloudinary.com/dqh6dvohu/image/upload/", string.Empty); var publicId = result.PublicId; var currentChannel = this.channelRepository.All().Where(c => c.Id == id).FirstOrDefault(); await this.CreateImage(imageUrl, publicId, currentChannel); }
public void TestEager() { var publicId = GetUniquePublicId(); // An array of breakpoints var uploadParams = new ImageUploadParams() { File = new FileDescription(m_testImagePath), PublicId = publicId, Tags = m_apiTag }; m_cloudinary.Upload(uploadParams); // responsive breakpoints for Explicit() var exp = new ExplicitParams(publicId) { EagerTransforms = new List <Transformation>() { m_simpleTransformation }, Type = STORAGE_TYPE_UPLOAD, Tags = m_apiTag }; ExplicitResult expResult = m_cloudinary.Explicit(exp); Assert.NotZero(expResult.Eager.Length); Assert.NotNull(expResult.Eager[0]); Assert.AreEqual(expResult.Eager[0].SecureUrl, expResult.Eager[0].SecureUrl); Assert.AreEqual(expResult.Eager[0].Url, expResult.Eager[0].Url); Assert.NotZero(expResult.Eager[0].Width); Assert.NotZero(expResult.Eager[0].Height); Assert.NotNull(expResult.Eager[0].Format); Assert.NotZero(expResult.Eager[0].Bytes); Assert.NotNull(expResult.Eager[0].Transformation); }
public PhotoUploadResult AddPhoto(IFormFile file) { var uploadResult = new ImageUploadResult(); if (file != null) { Console.WriteLine(file.ContentDisposition); Console.WriteLine(file.ContentType); Console.WriteLine(file.FileName); Console.WriteLine(file.Headers); Console.WriteLine(file.Length); } if (file.Length > 0) { using (var stream = file.OpenReadStream()) { var uploadParams = new ImageUploadParams { File = new FileDescription(file.FileName, stream), Transformation = new Transformation().Height(500).Width(500).Crop("fill").Gravity("face") }; uploadResult = _cloudinary.Upload(uploadParams); } } if (uploadResult.Error != null) { throw new Exception(uploadResult.Error.Message); } return(new PhotoUploadResult { PublicId = uploadResult.PublicId, Url = uploadResult.SecureUri.AbsoluteUri }); }
public RawUploadResult Upload() { RawUploadResult result = null; if (HttpContext.Current.Request.Files.AllKeys.Any()) { var httpPostedFile = HttpContext.Current.Request.Files["file"]; try { if (httpPostedFile.ContentType == "video/mp4") { var videoUploadParams = new VideoUploadParams() { File = new FileDescription(httpPostedFile.FileName, httpPostedFile.InputStream) }; result = cloudinary.Upload(videoUploadParams); } else { Stream processedImg = httpPostedFile.ContentType == "image/gif" ? httpPostedFile.InputStream : ResizeUploadImage(httpPostedFile.InputStream, null, null); var imageUploadParams = new ImageUploadParams() { File = new FileDescription(httpPostedFile.FileName, processedImg) }; result = cloudinary.Upload(imageUploadParams); } } catch (Exception ex) { throw new Exception(ex.Message, ex.InnerException); } } return(result); }
public async Task <IActionResult> AddScreenshotForGame(int gameId, [FromForm] ScreenshotForCreationDto screenshotForCreationDto) { var gameFromRepo = await _repo.GetGame(gameId); var file = screenshotForCreationDto.File; var uploadResult = new ImageUploadResult(); if (file.Length > 0) { using (var stream = file.OpenReadStream()) { var uploadParams = new ImageUploadParams() { File = new FileDescription(file.Name, stream), Transformation = new Transformation().Width(500).Height(500).Crop("fill").Gravity("face") }; uploadResult = _cloudinary.Upload(uploadParams); } } screenshotForCreationDto.Url = uploadResult.Url.ToString(); screenshotForCreationDto.PublicId = uploadResult.PublicId; var screenshot = _mapper.Map <Screenshot>(screenshotForCreationDto); gameFromRepo.Screenshots.Add(screenshot); if (await _repo.SaveAll()) { var screenshotToReturn = _mapper.Map <ScreenshotForReturnDto>(screenshot); return(CreatedAtRoute("GetScreenshot", new { gameId = gameId, id = screenshot.Id }, screenshotToReturn)); } return(BadRequest("Could not add the photo")); }
public ActionResult AddPhotoForCity([FromForm] PhotoForCreationDto photoForCreationDto) { /* * var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); * * if (currentUserId == null) * { * return Unauthorized(); * } */ var file = photoForCreationDto.File; var uploadResult = new ImageUploadResult(); if (file.Length > 0) { using (var stream = file.OpenReadStream()) { var uploadParams = new ImageUploadParams { File = new FileDescription(file.Name, stream) }; uploadResult = _cloudinary.Upload(uploadParams); } } //photoForCreationDto.Url = uploadResult.Uri.ToString(); // Uri KULLANILMIYOR photoForCreationDto.Url = uploadResult.Url.ToString(); photoForCreationDto.PublicId = uploadResult.PublicId; var photo = _mapper.Map <Photo>(photoForCreationDto); _photoRepository.Add(photo); _photoRepository.SaveAll(); return(Ok(photo)); }