Exemplo n.º 1
0
 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."));
     }
 }
Exemplo n.º 2
0
 public async Task <HttpResponseMessage> UploadFilesAsync(IFormFileCollection files, UsingForType type = UsingForType.Avatar)
 {
     return(await PostAsJsonAsync(UPLOAD_FILE_MULTIPLE, files));
 }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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}");
        }
Exemplo n.º 6
0
        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)));
        }
Exemplo n.º 7
0
 public async Task <HttpResponseMessage> UploadFilesAsync(IFormFileCollection files, UsingForType type = UsingForType.Avatar)
 {
     return(await _oppJarProxy.UploadFilesAsync(files, type));
 }
Exemplo n.º 8
0
 public async Task <HttpResponseMessage> UploadFileAsync(IFormFile file, string id, UsingForType type = UsingForType.Avatar)
 {
     return(await _oppJarProxy.UploadFileAsync(file, id, type));
 }