所需的多部分文件参数不存在

required multipartfile parameter is not present

我正在尝试通过我的其余网络服务上传图片,但是当涉及到多部分形式的数据时,它给我错误

HTTP Status 400 - Required MultipartFile parameter 'image' is not present

下面是我上传图片的函数

public String uploadImages(String json, File file) 
 {
     try {
         HttpClient httpClient = new DefaultHttpClient();
         HttpContext localContext = new BasicHttpContext();
         HttpPost httpPost = new HttpPost(url + "?jsondata="+URLEncoder.encode(json));
         httpPost.setHeader("content-type", "Multipart/Form-data;boundary=*****");
         MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);         
         entity.addPart("image", new FileBody(file));
         httpPost.setEntity(entity);
         HttpResponse response = httpClient.execute(httpPost,localContext);
         BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));

         String sResponse = reader.readLine();
         return sResponse;
     } catch (Exception e) 
     {
         Log.e(e.getClass().getName(), e.getMessage(), e);
         return null;
     }
 }  

我正在通过我的多部分实体传递 'image' 参数,但仍然出现此错误。

试试这个,

  private String fileUpload()
        {
            String strRes = "";
            HttpParams params = new BasicHttpParams();
            params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
            mHttpClient = new DefaultHttpClient(params);

            try
            {
                HttpPost httppost = new HttpPost(this.url);
                httppost.addHeader("enctype", "multipart/form-data");

                MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

                File filebody = new File(filepath);
                multipartEntity.addPart("imagepath", new FileBody(filebody));


                httppost.setEntity(multipartEntity);

                HttpResponse response = mHttpClient.execute(httppost);
                // mHttpClient.execute(httppost, new PhotoUploadResponseHandler());
                HttpEntity r_entity = response.getEntity();
                strRes = EntityUtils.toString(r_entity);
                resultCode = 1;
            }
            catch (Exception e)
            {
                e.printStackTrace();
                resultCode = 2;
            }
            return strRes;
        }**