Created
September 15, 2021 20:00
-
-
Save lokcito/9ec63afc74067607e7d959a70be32852 to your computer and use it in GitHub Desktop.
C# Upload imagen FromForm , Multipart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FIleUploadAPI | |
{ | |
public IFormFile oneimage { get; set; } | |
public String cellNumber { get; set; } | |
public String otroCampo { get; set; } | |
public String otroCampo2 { get; set; } | |
} | |
[Route("/api/v1/student/CAU/Ticket/new")] | |
[HttpPost] | |
public String postre([FromForm] FIleUploadAPI formdata) | |
{ | |
if (!ModelState.IsValid) | |
{ | |
return "Unsuccessful"; | |
} | |
if (formdata.oneimage.Length > 0) | |
{ | |
try | |
{ | |
if (!Directory.Exists("/Users/plaga/Documents/dev/media")) | |
{ | |
Directory.CreateDirectory("/Users/plaga/Documents/dev/media"); | |
} | |
using (FileStream filestream = System.IO.File.Create("/Users/plaga/Documents/dev/media/" + formdata.oneimage.FileName)) | |
{ | |
formdata.oneimage.CopyTo(filestream); | |
filestream.Flush(); | |
return "/Users/plaga/Documents/dev/media/" + formdata.oneimage.FileName; | |
} | |
} | |
catch (Exception ex) | |
{ | |
return ex.ToString(); | |
} | |
} | |
else | |
{ | |
return "Unsuccessful"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment