我试图使用Sending images using Http Post将图像发送到REST服务。该职位退出内容丰富,但我在FileBody bin1 = new FileBody(file);
处遇到编译错误。
错误:The constructor FileBody(File[]) is undefined
哪个是怪异的,因为我定义了它,为什么会发生这种情况,以及解决该问题的解决方案是什么?
任何帮助是极大的赞赏。
代码来源:
private class ImageUpload extends AsyncTask<File, Void, String> {
@Override
protected void onPreExecute() {
if (checkNullState() == false) {
showMyDialog();
}
}
protected String doInBackground(File... file) {
String imageDescriptionTemp = "Photo Temp Description.";
String PostRequestUri = "https://demo.relocationmw.com/ws_docmgmt/Service1.svc";
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(PostRequestUri);
FileBody bin1 = new FileBody(file);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("Image", bin1);
post.setEntity(entity);
HttpResponse response = client.execute(post);
resEntity = response.getEntity();
final String response_string = EntityUtils.toString(resEntity);
if(resEntity != null){
Log.i("RESPONSE", response_string);
}else{
return null;}
}
@Override
protected void onPostExecute(String result) {
if (checkNullState() == true) {
dismissMyDialog();
}
// add location once we have that figured out.
Toast.makeText(HomeActivity.this, "Image can be viewed {Location}",
Toast.LENGTH_LONG).show();
}
protected void onProgressUpdate(Map... values) {
}
最佳答案
我想你想要的是
FileBody bin1 = new FileBody(file[0]);
因为
doInBackground
使用varargs。所以下面的代码行:doInBackground(Params... params)
相当于
doInBackground(Params[] params)
而当你这样做
FileBody bin1 = new FileBody(file)
file
是一个数组(我想您已经定义了这样的构造函数,例如FileBody(File file)
)