目前我正在创建一个使用 IntelXDK 将图像从设备上传到我的服务器的应用程序。目前我遇到的问题是,如何对我的后端进行编码,以便它可以接收来自移动设备的上传文件?
在PHP中,我只知道文件上传需要:
- <input type="file" name="file" />
- 然后使用 $FILES["file"] 将其保存到存储中
并且在.Net 中也几乎相似。但是我仍然想不出通过手机上传文件后如何接收文件。如果有人分享或建议缺少的部分(.Net 和 PHP),那就太好了。
有关将文件上传到服务器的更多信息:https ://software.intel.com/en-us/node/493213
如果您了解 ASP.NET Web API 2,请查看此示例:
http://aspnet.codeplex.com/sourcecontrol/latest#Samples/WebApi/FileUploadSample/
另外,检查这些:
http://damienbod.wordpress.com/2014/03/28/web-api-file-upload-single-or-multiple-files/
http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2
http://www.c-sharpcorner.com/UploadFile/2b481f/uploading-a-file-in-Asp-Net-web-api/
检查这些 SO 链接:
我认为,通过以上链接,您肯定能够创建从表单上传文件的服务。
希望对你有帮助...
一切顺利...
在 ASP.net 服务器端使用字节格式的 web 服务接收并根据需要保存。
代码示例参考链接http://www.codeproject.com/Articles/22985/Upload-Any-File-Type-through-a-Web-Service
[网络方法]
public string UploadFile(byte[] f, string fileName)
{
// the byte array argument contains the content of the file
// the string argument contains the name and extension
// of the file passed in the byte array
try
{
// instance a memory stream and pass the
// byte array to its constructor
MemoryStream ms = new MemoryStream(f);
// instance a filestream pointing to the
// storage folder, use the original file name
// to name the resulting file
FileStream fs = new FileStream
(System.Web.Hosting.HostingEnvironment.MapPath
("~/TransientStorage/") +
fileName, FileMode.Create);
// write the memory stream containing the original
// file as a byte array to the filestream
ms.WriteTo(fs);
// clean up
ms.Close();
fs.Close();
fs.Dispose();
// return OK if we made it this far
return "OK";
}
catch (Exception ex)
{
// return the error message if the operation fails
return ex.Message.ToString();
}
}
}
}