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);
}