0
我有C#如何将多个文件发送到web服务
[HttpPost]
public JsonResult PostFileToServers(HttpPostedFileBase[] files)
{
foreach (var file in files)
{
var fileStorage = @"C:\Users\Aka\Dropbox\SMAC\file-upload";
if (!Directory.Exists(fileStorage))
Directory.CreateDirectory(fileStorage);
var fileName = Path.Combine(fileStorage, string.Format("{0}.wav", DateTime.Now));
file.SaveAs(fileName);
}
var jsonResponseModel = new JsonResponseModel();
jsonResponseModel.Status = (int)ResponseStatus.Successful;
return Json(jsonResponseModel);
}
我想通过上面的Web服务发送android的多个文件编写一个Web服务。这是我的代码,但它没有发送文件到Webservice。任何人都有解决方案?
public void uploadtoserver(String filepath1,String filepath2,String filepath3) throws IOException
{
HttpClient client = new DefaultHttpClient();
HttpResponse response = null;
HttpPost httpost = new HttpPost(URL);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
File file1 = new File (filepath1);
File file2 = new File (filepath2);
File file3 = new File (filepath3);
entity.addPart("files[0]", new FileBody(file1));
entity.addPart("files[1]", new FileBody(file2));
entity.addPart("fIles[2]", new FileBody(file3));
httpost.setEntity(entity);
response = client.execute(httpost);
}