protected void Page_Load(object sender, EventArgs e) { string routeName = Request.QueryString["Route"]; UploadedImages list = UploadedImages.FromSession(routeName); string temporaryFolder = PathFunctions.GetTempPath(); for (int i = 0; i < Request.Files.Count; i++) { try { HttpPostedFile file = Request.Files[i]; //creo un nuovo file in session string filePath = Path.Combine(temporaryFolder, string.Format("{0}-{1}.jpg", (list.Count + 1).ToString("000"), routeName)); UploadedImage ui = new UploadedImage(filePath, file.InputStream); if (string.IsNullOrEmpty(ui.Description)) { ui.Description = Path.GetFileNameWithoutExtension(file.FileName); } list.Add(ui); } catch { //file non valido, mancato upload! } } }
private bool UploadAction(string filePath) { var uploadParams = new ImageUploadParams { File = new FileDescription(filePath), Colors = true, Backup = true, AccessMode = "public", UseFilename = true }; var result = _cloudinary.Upload(uploadParams); if (result.Error != null) { FailedUploads.Enqueue(filePath); _logger.LogWarning($"Upload failed for {filePath} at {DateTime.Now.ToLongDateString()}"); return(false); } UploadedImages.Add(filePath); PhotosUrls.Add(result.SecureUri.AbsoluteUri); _logger.LogInformation($"Image with id: {result.PublicId} was uploaded at {DateTime.Now.ToLongDateString()} with accesible url: {result.SecureUri.AbsoluteUri}"); return(true); }