Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中使用MultipartEntity类进行图像上传_Android - Fatal编程技术网

android中使用MultipartEntity类进行图像上传

android中使用MultipartEntity类进行图像上传,android,Android,我必须上传图像文件并将其发送到服务器,所以我使用MultipartEntity类,它会给我以下错误消息 Multiple markers at this line - MultipartEntity cannot be resolved to a type - The type new RecoverySystem.ProgressListener(){} must implement the inherited abstract method RecoverySystem.Progres

我必须上传图像文件并将其发送到服务器,所以我使用MultipartEntity类,它会给我以下错误消息

Multiple markers at this line

- MultipartEntity cannot be resolved to a type
- The type new RecoverySystem.ProgressListener(){} must implement the inherited abstract method 
 RecoverySystem.ProgressListener.onProgress(int)
- MultipartEntity cannot be resolved to a type
这是密码

@Override
    protected String doInBackground(Void... params) {
        return uploadFile();
    }

    @SuppressWarnings("deprecation")
    private String uploadFile() {
        String responseString = null;

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://politician.qkzoom.com");
        return responseString;



        MultipartEntity entity = new MultipartEntity(new ProgressListener() {

            public void transferred(long num) {

                publishProgress((int) ((num / (float) totalSize) * 100));
            }
        });

您可以通过将图像转换为Base64字符串并将该字符串发送到服务器,然后在服务器端解码Base64字符串来上传图像 此代码将图像转换为Base64字符串

public static final String convertImageToBase64(Bitmap bm) {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); // bm is the bitmap
                                                            // object
        byte[] byteArrayImage = baos.toByteArray();

        return Base64.encodeToString(byteArrayImage, Base64.DEFAULT);
    }
这是你惯用的进口货

import java.io.ByteArrayOutputStream;
import android.graphics.Bitmap;
import android.util.Base64;

你能写下MultipartEntity的完整类名吗?