0

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

但是当我尝试使用下面的代码时,我得到 class not found 错误,并且图像无法上传。

现在我重新启动 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();
        }
4

0 回答 0