Here is the Api code
public class FileUploadAPI { public IFormFile files { get; set; } } // POST: api/Image [HttpPost] public async Task Post(FileUploadAPI obj) { var uploads = Path.Combine(_environment.WebRootPath, "upload"); if (obj.files.Length > 0) { using (var fileStream = new FileStream(Path.Combine(uploads, obj.files.FileName), FileMode.Create)) { await obj.files.CopyToAsync(fileStream); } } }
it works will i am using potman to send iamge
I tried to send image from xamarin forms application by following @AdamBennett.7253 code https://forums.xamarin.com/discussion/comment/391872#Comment_391872 here is the client side code but its not working
private async void testuplo_Clicked(object sender, EventArgs e) { //variable var url = "http://localhost:4622/api/image"; //variable // var url = "http://hallpassapi.jamsocialapps.com/api/profile/UpdateProfilePicture/"; // var file = "C:/Users/MIS/source/repos/CCNPP/CCNPP/Images/Communitiesreached.png"; var media = CrossMedia.Current; var file = await media.PickPhotoAsync(); // wait until the file is written while (File.ReadAllBytes(file.Path).Length == 0) { System.Threading.Thread.Sleep(1); } try { //read file into upfilebytes array var upfilebytes = File.ReadAllBytes(file.Path); //create new HttpClient and MultipartFormDataContent and add our file, and StudentId HttpClient client = new HttpClient(); MultipartFormDataContent content = new MultipartFormDataContent(); ByteArrayContent baContent = new ByteArrayContent(upfilebytes); //StringContent studentIdContent = new StringContent("2123"); content.Add(baContent, "files", "03-0302-M0018_6464_He_5.jpg"); //content.Add(studentIdContent, "StudentId"); //upload MultipartFormDataContent content async and store response in response var var response = await client.PostAsync(url, content); //read response result as a string async into json var var responsestr = response.Content.ReadAsStringAsync().Result; //debug Console.WriteLine(responsestr); } catch (Exception ex) { //debug Console.WriteLine("Exception Caught: " + ex.Message.ToString()); return; } }