Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have a Linux code for an API call to upload an image.

Linux
curl -H ’Authorization: Bearer 1-N’ -D - -k \
  -F "image[]=@Freddie_Mercury.jpg;type=image/jpeg" \
   http://localhost:8080/v1/auction-lot/1-1CM/image; echo
   HTTP/1.1 100 Continue



How this can be implemented in C# code. I have done the following

C#
imageBytes = webClient.DownloadData(Freddie_Mercury.jpg);
var client = new WebClient();
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";          Dictionary<string, string> value = new Dictionary<string,string>();
value.Add("image[]", Convert.ToBase64String(imageBytes));
System.Net.Http.FormUrlEncodedContent test = new System.Net.Http.FormUrlEncodedContent(value);
resp = client.UploadString(url,test.ToString());




It shows a bad request error. Please help me.
Posted
Updated 17-Sep-15 0:32am
v2
Comments
Leo Chapiro 17-Sep-15 5:47am    
Do you mean imageBytes = webClient.DownloadData("Freddie_Mercury.jpg"); ?
What command raise an error?
Please put your code in try / catch ...
Baiju christadima 17-Sep-15 6:06am    
Thanks for your feed back

resp=client.uploadstring(url,test.Tostring()); showing the error
The error response is "Bad request"
[no name] 25-Jun-16 3:53am    
This is probably what you need :
https://msdn.microsoft.com/en-us/library/36s52zhs(v=vs.110).aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900