public async Task <ResponseStructure> UploadAudio(IFormFile file, string fireFlag, string loc) { try { string ftype = file.ContentType; if ((ftype == "audio/mp3" || ftype == "audio/mpeg")) { string uploadPath = FileLocMapper.LocateMediaFile(fireFlag, loc); //long fsize = file[i].Length; string fname = DateTime.UtcNow.Millisecond + UtilesService.GenerateNewRandom() + "." + System.IO.Path.GetExtension(file.FileName).Substring(1); var filePath = Path.Combine(uploadPath, fname); using (var stream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(stream); } return(ResponseModel.Success(msg: "فایل صوتی با موفقیت آپلود گردید", data: fname)); } else { return(ResponseModel.Error("نوع فایل ارسال شده صحیح نمیباشد")); } } catch (Exception e) { return(ResponseModel.Error("خطای ناشناخته در سیستم رخ داده است" + e.Message)); } }
public async Task <ResponseStructure> uploadDocument(IFormFile file, string fireFlag, string loc) { try { string[] allowtype = new string[] { "application/msword", "application/vnd.ms-excel", "application/vnd.ms-powerpoint", "text/plain", "application/pdf" }; string ftype = file.ContentType; if ((allowtype.Contains(ftype))) { string uploadPath = FileLocMapper.LocateMediaFile(fireFlag, loc); //long fsize = file[i].Length; string fname = DateTime.UtcNow.Millisecond + UtilesService.GenerateNewRandom() + "." + System.IO.Path.GetExtension(file.FileName).Substring(1); var filePath = Path.Combine(uploadPath, fname); using (var stream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(stream); } return(ResponseModel.Success(msg: "فایل با موفقیت آپلود گردید", data: fname)); } else { return(ResponseModel.Error("نوع فایل ارسال شده صحیح نمیباشد")); } } catch (Exception e) { return(ResponseModel.Error("خطای ناشناخته در سیستم رخ داده است" + e.Message)); } return(null); }