android中使用MultipartEntity类进行图像上传
我必须上传图像文件并将其发送到服务器,所以我使用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
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的完整类名吗?