public async Task <IActionResult> UploadFileViaModel(FileInputModel model) { if (model == null || model.FileToUpload == null || model.FileToUpload.Length == 0) { return(Content("file not selected")); } var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot", model.FileToUpload.GetFilename()); using (var stream = new FileStream(path, FileMode.Create)) { await model.FileToUpload.CopyToAsync(stream); } return(RedirectToAction("Files")); }
public ActionResult AddFile(FileInputModel model) { if (ModelState.IsValid == false) { this.TempData["fileUploadState"] = "Invalid file."; return(this.RedirectToAction("Index", routeValues: new { directory = model.CurrentDirectory })); } string fullPath = Server.MapPath("~" + RelativePath + "\\" + model.CurrentDirectory); if (Directory.Exists(fullPath) == false) { this.TempData["fileUploadState"] = "Invalid directory."; return(this.RedirectToAction("Index", routeValues: new { directory = model.CurrentDirectory })); } string fileFullPath = fullPath + "\\" + model.File.FileName; if (new FileInfo(fileFullPath).Exists == true) { this.TempData["fileUploadState"] = "File name exists!"; return(this.RedirectToAction("Index", routeValues: new { directory = model.CurrentDirectory })); } if (model.File.ContentLength <= 2048000) { model.File.SaveAs(fileFullPath); FileInfo fileInfo = new FileInfo(fileFullPath); if (fileInfo == null) { this.TempData["fileUploadState"] = "Error! File was not saved!"; } } else { this.TempData["fileUploadState"] = "Error! File is to big!"; } return(this.RedirectToAction("Index", routeValues: new { directory = model.CurrentDirectory })); }
public IActionResult CheckContentDocument([FromForm] FileInputModel Files, CancellationToken cancellationToken) { try { if (Files.File == null) { throw new Exception("No File was uploaded"); } if (!this.profanityCheckSvc.AcceptedExtensions.Any(ext => Files.File.FileName.EndsWith(ext))) { throw new Exception($"Invalid file extensions. " + $"Expected ${string.Join(',', this.profanityCheckSvc.AcceptedExtensions.ToArray())}."); } using (MemoryStream ms = new MemoryStream()) { Files.File.CopyTo(ms); var textContent = Encoding.UTF8.GetString(ms.ToArray()); var result = this.profanityCheckSvc.GetViolatedWords(textContent); return(Ok(new ProfanityCheckResponse() { Success = true, Data = new ProfanityCheckValue() { ViolatedWords = result.ToList() } })); } } catch (Exception ex) { return(Ok(new ErrorResponse() { Data = ex.Message })); } }
public dynamic guardarProyecto([FromForm] FileInputModel proyectoRequest) { var excelLargo = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; if (proyectoRequest.File.ContentType.Contains("application/vnd.ms-excel") || proyectoRequest.File.ContentType.Contains("application/pdf") || proyectoRequest.File.ContentType.Contains("contenidoapplication/octet-stream") || proyectoRequest.File.ContentType.Contains(excelLargo)) { var data = _dataModelRepository.UploadFileAsync(proyectoRequest); return(new { id = 0, status = "OK", code = 200 }); } else { return(new { code = 200, status = "error", message = "No se permite este tipo de contenido" + proyectoRequest.File.ContentType }); } }
//public async Task<IActionResult> UploadFileViaModel(FileInputModel model) //{ // if (model == null || // model.FileToUpload == null || model.FileToUpload.Length == 0) // return Content("file not selected"); // var path = Path.Combine( // Directory.GetCurrentDirectory(), "wwwroot", // model.FileToUpload.GetFilename()); // using (var stream = new FileStream(path, FileMode.Create)) // { // await model.FileToUpload.CopyToAsync(stream); // } // return RedirectToAction("Files"); //} // , string username = "******", string password = "******" // username == "hasan" && password == "12345" && public async Task <IActionResult> UploadFileViaModel(FileInputModel model) { if (model.Username == "Hasan" && model.Password == 12345 && model.FileToUpload != null && model.FileToUpload.Count > 0) { foreach (IFormFile file in model.FileToUpload) { var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot", file.GetFilename()); using (var stream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(stream); } } } else { return(Content("file not selected")); } return(RedirectToAction("Files")); }
public async Task <IActionResult> UploadFile([FromForm] FileInputModel std) { // Getting Name var id = std.EmpleadoID; // Getting Image var image = std.Photo; // Saving Image on Server var path = Path.Combine(Directory.GetCurrentDirectory(), "C:\\Users\\marti\\OneDrive\\Escritorio\\paginas\\ConsumoApiBellaUnion\\src\\images\\imagenes_perfil", id + "_" + image.FileName); var empleado = _context.Empleado.Find(id); if (image.Length > 0) { using (var fileStream = new FileStream(path, FileMode.Create)) { await image.CopyToAsync(fileStream); empleado.Photo = id + "_" + image.FileName; await _context.SaveChangesAsync(); } } return(Ok(new { status = true, message = "Student Posted Successfully" })); }
public async Task <IActionResult> UploadFile([FromForm] FileInputModel file) { try { if (file.FileToUpload == null || file.FileToUpload.Length == 0) { throw new ArgumentNullException("file null"); } var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\images", file.FileToUpload.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await file.FileToUpload.CopyToAsync(stream); } return(Ok(file)); } catch { throw new ArgumentNullException("file not selected"); } }
public async Task <IActionResult> UpdateFilePartiallyByFileId([FromBody] FileInputModel body, int fileId) { var token = Request.Headers["Authorization"]; var authToken = token.ToString(); // If Authorization header is not present // throw error if (string.IsNullOrEmpty(authToken)) { throw new RequestElementsNeededException(); } var queryString = Request.QueryString.ToString(); // If Querystring is empty throw error if (string.IsNullOrEmpty(queryString)) { throw new RequestElementsNeededException(); } var userName = queryString.Split('=') [1]; var result = await Validate(authToken, userName); _metaService.UpdateFilePartiallyByFileId(body, fileId); return(NoContent()); }
public async Task <IActionResult> UploadFile(FileInputModel inputModel) { if (inputModel == null) { return(Content("Argument null")); } if (inputModel.File == null || inputModel.File.Length == 0) { return(Content("file not selected")); } var blobName = inputModel.File.GetFilename(); var fileStream = await inputModel.File.GetFileStream(); if (!string.IsNullOrEmpty(inputModel.Folder)) { blobName = string.Format(@"{0}\{1}", inputModel.Folder, blobName); } await blobStorage.UploadAsync(blobName, fileStream); return(RedirectToAction("Index")); }
public bool AddItemsToBoard(FileInputModel uploadBoard) { var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "assets"); var board = LoadBoard(uploadBoard.id); if (board != null) { bool IsUploadOk = false; foreach (var item in uploadBoard.files) { var fullpath = FileHelper.UploadFile(uploads, item, ShaHelper.GenerateSHA256String(DateTime.Now.ToString())); if (fullpath == null) { IsUploadOk = false; break; } board.Items.Add(new SharedBoardItemBoard() { Name = item.FileName, ShortText = "", Path = fullpath, Type = SharedBoardItemBoard.ItemBoardType.Image }); IsUploadOk = true; } if (IsUploadOk) { UpdateBoard(board); } } return(true); }
public void UpdateFilePartiallyByFileId(FileInputModel body, int fileId) { _metaRepository.UpdateFilePartiallyByFileId(body, fileId); }
public int CreateFileByUserId(FileInputModel body, int userId) { return(_metaRepository.CreateFileByUserId(body, userId)); }
public async Task <IActionResult> OnPostFileAsync(int id, FileInputModel fileCommand) => await ProceedCommand(id, fileCommand);
public async Task <IActionResult> UploadFileViaModel(FileInputModel model) { if (model == null || model.FileToUpload == null || model.FileToUpload.Length == 0) { return(Content("file not selected")); } string secretKey = model.SecretKey; var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot/epin", model.FileToUpload.GetFilename()); string fileName = Path.GetFileNameWithoutExtension(model.FileToUpload.GetFilename()); string sFileExtension = Path.GetExtension(fileName).ToLower(); string inputFile = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/epin", model.FileToUpload.GetFilename()); string outputFile = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/epin", "decry_" + fileName); // save encrypted file using (var stream = new FileStream(path, FileMode.Create)) { await model.FileToUpload.CopyToAsync(stream); } // decrypt file try { byte[] key = ASCIIEncoding.UTF8.GetBytes(secretKey); byte[] IV = ASCIIEncoding.UTF8.GetBytes(secretKey); RijndaelManaged aes = new RijndaelManaged(); aes.Mode = CipherMode.ECB; aes.Padding = PaddingMode.PKCS7; ICryptoTransform decryptor = aes.CreateDecryptor(key, IV); CryptoStream cs = new CryptoStream(model.FileToUpload.OpenReadStream(), decryptor, CryptoStreamMode.Read); FileStream fsOut = new FileStream(outputFile, FileMode.Create); int data; while ((data = cs.ReadByte()) != -1) { fsOut.WriteByte((byte)data); } model.FileToUpload.OpenReadStream().Close(); fsOut.Close(); cs.Close(); } catch (Exception ex) { // failed to decrypt file Console.WriteLine("Errors : " + ex.Message); } // File Download var memory = new MemoryStream(); using (var stream = new FileStream(outputFile, FileMode.Open)) { await stream.CopyToAsync(memory); } memory.Position = 0; return(File(memory, GetContentType(outputFile), Path.GetFileName(outputFile))); }