问题
I'm trying to create the wcf service which will upload the files like pdf,doc,xls,images but pdf, txt files are uploading and opening properly but when i'm trying to upload the image file then the file is getting uploaded but the image is not visible
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "Upload/{fileName}")]
string Upload(string fileName, Stream fileContents);
using (FileStream fs = new FileStream("my path", FileMode.Create))
{
fileContents.CopyTo(fs);
fileContents.Close();
}
回答1:
try byte array instead of stream and wrapping the class like this:
public class Input
{
[DataMember]
public string fileName { get; set; }
[DataMember]
public byte[] fileContents { get; set; }
}
then simply write the file on disk like this:
public string Upload(Input input)
{
File.WriteAllBytes(input.fileName, input.fileContents);
return "OK";
}
回答2:
@mohammad check the below image how i'm trying to upload the image file how i'm trying to upload the image file
Thanks
来源:https://stackoverflow.com/questions/41849403/how-to-upload-the-image-from-the-stream-in-wcf-rest-service