MultipartEntity图片上传无法正常工作

时间:2013-04-12 14:44:17

标签: android

我想使用MultipartEntity上传图片,我添加了所有外部jar文件。

但是当我尝试使用下面的代码时,我发现找不到类错误,而且图片无法上传。

现在我重启eclipse,现在我得到了像

这样的错误

无法执行dex:多个dex文件定义Lorg / apache / http / entity / mime / FormBodyPart;

转换为Dalvik格式失败:无法执行dex:多个dex文件定义Lorg / apache / http / entity / mime / FormBodyPart;

下面是我的php文件和java代码。

<?php
$photo = $_FILES['photo']['name'];


    if(!empty($_FILES['photo']['name']))
    {
        move_uploaded_file($_FILES['photo']['tmp_name'], "User_files/".$_FILES['photo']['name']);
    }

?>

  DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(URL);

        File file = new File(Environment.getExternalStorageDirectory()+"/a.png");

        //Log.d(TAG, "UPLOAD: setting up multipart entity");

        MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        //Log.d(TAG, "UPLOAD: file length = " + file.length());
        //Log.d(TAG, "UPLOAD: file exist = " + file.exists());

        mpEntity.addPart("photo", new FileBody(file, "image/png"));
        //mpEntity.addPart("id", new StringBody("1"));
        httppost.setEntity(mpEntity);
        HttpResponse response;
        try {
            response = httpclient.execute(httppost);
            HttpEntity resEntity = response.getEntity();
            }
            if (resEntity != null) {
                resEntity.consumeContent();
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

0 个答案:

没有答案