1

我正在尝试使用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) {
        }
4

1 回答 1

1

我认为你想要的是

FileBody bin1 = new FileBody(file[0]);

因为doInBackground使用varargs。所以下面的代码行:

doInBackground(Params... params)

相当于

doInBackground(Params[] params)

当你这样做时

FileBody bin1 = new FileBody(file)

file是一个数组(我想你已经定义了这样的构造函数FileBody(File file)

于 2013-04-10T21:50:18.953 回答