public async Task <IActionResult> ImageUplpoad(IFormFile file, string userId) { try { ////check the image file is valid or not and email address is not null if (!file.Equals(null) && !userId.Equals(null)) { ////businessManager layer method called. var imageUrl = await this.businessManager.ImageUpload(file, userId); ////check the cloudinary image url is not null if (!imageUrl.Equals(null)) { ////return the cloudinary image url return(this.Ok(new { imageUrl })); } else { ////return the bad result if return(this.BadRequest(new { Message = "Image not uploaded on Cloudinary" })); } } else { ////return the bad request file or email is null return(this.BadRequest(new { Message = "Please select valid Image file or valid email" })); } } catch (Exception ex) { ////throw the exception throw new Exception(ex.Message); } }
public string SaveFile(IFormFile file, string path, string organizationId, string apiComponent, string binaryObjectId) { //save file to OpenBots.Server.Web/BinaryObjects/{organizationId}/{apiComponent}/{binaryObjectId} apiComponent = apiComponent ?? string.Empty; var target = Path.Combine(path, organizationId, apiComponent); if (!directoryManager.Exists(target)) { directoryManager.CreateDirectory(target); } var filePath = Path.Combine(target, binaryObjectId); if (file.Length <= 0 || file.Equals(null)) { return("No file exists."); } if (file.Length > 0) { using (var stream = new FileStream(filePath, FileMode.Create)) { file.CopyTo(stream); } ConvertToBinaryObject(filePath); } return(binaryObjectId); }
/// <summary> /// /// </summary> /// <param name="formFile"></param> /// <returns></returns> public async Task <string> ImageUploadWhileCratingNote(IFormFile formFile) { try { if (!formFile.Equals(null)) { ////RepositoryLayer method called var result = await this.repositoryManager.ImageUploadWhileCratingNote(formFile); if (!result.Equals(null)) { return(result); } else { throw new Exception(); } } else { throw new Exception(); } } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// Image Upload. /// </summary> /// <param name="file">The file name.</param> /// <param name="email">User Email.</param> /// <returns>Return the Image url.</returns> public async Task <string> ImageUpload(IFormFile file, string userId) { try { if (!file.Equals(null) && !userId.Equals(null)) { var imageUrl = await this.userRepositoryManager.ImageUpload(file, userId); if (!imageUrl.Equals(null)) { return(imageUrl); } else { throw new Exception(); } } else { throw new Exception(); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public bool ArquivoNulloOuVazio(IFormFile file) { return(!file.Equals(null) && !file.Length.Equals(0)); }