For some reason, Im using WCF for webAPIs..I have been using WCF for few days now. On the hunt to find the code to upload image to the server I found many answers and solutions like:
Could not upload Image to WCF Rest service
Uploading image as attachment in RESTful WCF Service
Uploading an image using WCF RESTFul service full working example
the above (full woking) example is working for me..accept for the part that it accepts only jpeg images. Since im using Postman to hit on the request, Stream datatype is accepting it and run to the program. Is there anyway to get a file type or file name from input stream data?
Following is the code
interface:
Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
string PostImage(Stream stream);
method implementation:
public string PostImage(Stream stream)
{
byte[] buffer = new byte[10000];
stream.Read(buffer, 0, 10000);
FileStream f = new FileStream("C:\\temp\\sample.jpg", FileMode.OpenOrCreate);
f.Write(buffer, 0, buffer.Length);
f.Close();
return "Recieved the image on server";
}
PS: im using postman request to send image like the following simple browse file option under byte section like this:
PS: Along with the image, I cannot pass the file name if even i want to, since Stream parameter does not allow any other parameter with it.