【发布时间】:2014-07-31 08:14:26
【问题描述】:
已经好几天了,我仍然坚持这个图片上传的事情,我无法让它工作。我不会上传我的任何源代码,因为它看起来很可悲并且无法正常工作,所以我必须请求可以为我完成这项工作的人。我已经在谷歌上搜索了一段时间,但似乎无法让它们中的任何一个工作。
基本上我要做的是将位图上传到服务器,它必须作为 fileStream 发送,如下所示。就是这样。
无论如何,这里是 Web 服务的源代码。这将在 Android 设备发出 HttpPost 请求时触发。请注意,这不是我的代码。其他人负责这件事。
public Stream FileUpload(string fileName, Stream fileStream){
var serverPath = System.Web.Hosting.HostingEnvironment.MapPath("~/FileUpload/");
if (File.Exists(serverPath + fileName)) File.Delete(serverPath + fileName); // delete file if already used
//FileStream fileToupload = new FileStream("D:\\FileUpload\\" + fileName, FileMode.Create);
FileStream fileToupload = new FileStream(serverPath + fileName, FileMode.Create);
byte[] bytearray = new byte[10000];//
int bytesRead, totalBytesRead = 0;
do
{
bytesRead = fileStream.Read(bytearray, 0, bytearray.Length);
totalBytesRead += bytesRead;
} while (bytesRead > 0);
fileToupload.Write(bytearray, 0, bytearray.Length);
fileToupload.Close();
fileToupload.Dispose();
FileStream fs = File.OpenRead(serverPath + fileName);
WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
return fs;
}
非常感谢任何帮助。
【问题讨论】: