0

Sorry for the another question has already appearing everywhere. I'm very new to c# httpclient and I only need to write one small function for this once but I've been struggle to find a good example.

I'm building a windows store application using c# and I'm hoping to include a function to upload the file to my tomcat server through a web page I've created.

here is the piece of script to select a file and upload it to my server's drive.

<form method="post" action="uploadFile" enctype="multipart/form-data"> 
 <input   type="file" name="uploadFile" />  
 <input   type="submit" value="Upload" />
</form>

I've seen many answers regarding 'Upload httpclient(multipart/form-data)' but I haven't found one with easy to understand examples for rookies like me.

e.g. These answer answer seem really short but I have no idea how to apply it to my application. please let me know if there is any piece of example I can use to understand how to implement it.

update 1: this is what I have at the moment...but it seems not working and there is no error message

var filePath = System.IO.Path.Combine(pictureFolderPath, "Camera Roll", System.IO.Path.GetFileName(currentImagePath));
System.IO.Stream fileStream = System.IO.File.OpenRead(filePath);
System.Net.Http.HttpContent fileStreamContent = new System.Net.Http.StreamContent(fileStream);

using (var client = new System.Net.Http.HttpClient())
using (var formData = new System.Net.Http.MultipartFormDataContent())
{ 
formData.Add(fileStreamContent, "uploadFile"); 
var response = client.PostAsync("http://10.66.65.93:8080/web/", formData).Result;
var response2 = 1;
}

Thanks a lot

  • Possible duplicate of [Upload files with HTTPWebrequest (multipart/form-data)](https://stackoverflow.com/questions/566462/upload-files-with-httpwebrequest-multipart-form-data) – Bob Swager Jun 09 '17 at 14:10
  • What exactly do you mean by *"it seems not working"*? Do you receive some error code in response? Or request is not sent to server? Or server receive request but content is wrong? We are not able to help you without more details. – Ňuf Jun 09 '17 at 18:09

0 Answers0