public async Task <IActionResult> UploadFiles(IFormFileCollection files, UsingForType type = UsingForType.Avatar) { if (files.Count > 0) { return(Ok(await _fileService.UploadMultiFileAsync(files, type))); } else { return(BadRequest("No files to upload.")); } }
public async Task <HttpResponseMessage> UploadFilesAsync(IFormFileCollection files, UsingForType type = UsingForType.Avatar) { return(await PostAsJsonAsync(UPLOAD_FILE_MULTIPLE, files)); }
public async Task <HttpResponseMessage> UploadFileAsync(IFormFile file, string id, UsingForType type = UsingForType.Avatar) { byte[] data; using (var br = new BinaryReader(file.OpenReadStream())) data = br.ReadBytes((int)file.OpenReadStream().Length); ByteArrayContent bytes = new ByteArrayContent(data); MultipartFormDataContent multiContent = new MultipartFormDataContent { { bytes, "file", file.FileName } }; return(await _httpClient.PostAsync(string.Format(UPLOAD_FILE, id, type), multiContent)); }
public async Task <List <string> > UploadMultiFileAsync(IFormFileCollection files, UsingForType type = UsingForType.Avatar) { List <string> result = new List <string>(); foreach (var file in files) { result.Add(await UploadFileAsync(file)); } return(result); }
public async Task <string> UploadFileAsync(IFormFile file, string userId = null, UsingForType type = UsingForType.Avatar) { var fileName = file.FileName.RemoveSpecialCharacter(); string fileUrl = ""; string diskPath = string.Empty; var contentType = MimeTypes.GetMimeType(fileName); var extension = Path.GetExtension(fileName); Enum.TryParse(contentType.GetFileTypeByContentType(), out FileType fileType); fileName = $"{Guid.NewGuid().ToString()}{extension}"; FileHelper.SaveFile(ref diskPath, ref fileUrl, ref fileName, userId ?? UserId, file); var dbFile = new MediaFile { UserId = string.IsNullOrEmpty(userId) ? UserId : userId, DiskPath = diskPath, FileName = fileName, Url = fileUrl, Extension = contentType, CreatedDate = DateTime.UtcNow, FileType = fileType, UsingForType = type }; await CreateFileInformationAsync(dbFile); return($"{ApiUrl}{fileUrl}"); }
public async Task <IActionResult> UploadFile(IFormFile file, string userId = null, UsingForType type = UsingForType.Avatar) { if (file == null) { return(BadRequest("No file to upload.")); } return(Ok(await _fileService.UploadFileAsync(file, userId, type))); }
public async Task <HttpResponseMessage> UploadFilesAsync(IFormFileCollection files, UsingForType type = UsingForType.Avatar) { return(await _oppJarProxy.UploadFilesAsync(files, type)); }
public async Task <HttpResponseMessage> UploadFileAsync(IFormFile file, string id, UsingForType type = UsingForType.Avatar) { return(await _oppJarProxy.UploadFileAsync(file, id, type)); }