public async Task <UploadResult> Upload(IFormFile file) { var result = new UploadResult(); var fileInfo = new FileInfo(file.FileName); var targetFileName = $"{DateTime.UtcNow.ToString("yyyyMMHHddss")}{fileInfo.Extension}"; var targetPath = Path.Combine(_uploadFolder, targetFileName); while (await _blogStorage.Exists(new Blob { Identifier = targetPath, Name = targetFileName })) { targetFileName = $"{DateTime.UtcNow.ToString("yyyyMMHHddss")}{fileInfo.Extension}"; targetPath = Path.Combine(_uploadFolder, targetFileName); } var blob = new Blob { Identifier = targetPath, Name = targetFileName, }; blob = await _blogStorage.SaveBlob(blob, file.OpenReadStream()); result.Name = file.FileName; result.Url = blob.Uri; result.Size = blob.Size; result.ThumbnailUrl = GetThumbnailUrl(file.FileName, blob); return(result); }
public async Task <IActionResult> Get(string id, [FromQuery] int w = 100, [FromQuery] int h = 100) { if (!blobStorage.Exists(id)) { return(NotFound(new { Result = "error", Message = $"image {id}.jpeg does not exist" })); } if (w < 100 || h < 100) { return(BadRequest(new { Result = "error", Message = "width and height should be greater that or equal to 100." })); } var file = await blobStorage.LoadAsync(id); var(jpeg, mimeType) = imageProcessor.ToJpeg(file, w, h); return(File(jpeg, mimeType)); }
public async Task <UploadResult> Upload(IEnumerable <IFormFile> files) { var result = new UploadResult { Code = 0, Message = "Uploaded", Data = new UploadResult.ResultData { ErrFiles = new List <string>(), SuccMap = new Dictionary <string, string>() } }; foreach (var file in files) { try { var fileInfo = new FileInfo(file.FileName); var targetFileName = $"{DateTime.UtcNow.ToString("yyyyMMHHddss")}{fileInfo.Extension}"; var targetPath = Path.Combine(_uploadFolder, targetFileName); while (await _blogStorage.Exists(new Blob { Identifier = targetPath, Name = targetFileName })) { targetFileName = $"{DateTime.UtcNow.ToString("yyyyMMHHddss")}{fileInfo.Extension}"; targetPath = Path.Combine(_uploadFolder, targetFileName); } var blob = new Blob { Identifier = targetPath, Name = targetFileName, }; blob = await _blogStorage.SaveBlob(blob, file.OpenReadStream()); result.Data.SuccMap.Add(file.FileName, blob.Uri); } catch (Exception ex) { _Logger.Error($"Failed to upload file :{file.FileName}", ex); result.Data.ErrFiles.Add(file.FileName); } } return(result); }
public bool WorldStateExists() { return(storage.Exists("latest")); }