目标:获取图片(即其网址)并作为图片上传到服务器
方法尝试: 提取的图像URL>转换为位图>编码为base64>上传到服务器
public void UploadImageToServer() {
bmImg.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
byteArray = byteArrayOutputStream.toByteArray();
ConvertImage = Base64.encodeToString(byteArray, Base64.DEFAULT);
class AsyncTaskUploadClass extends AsyncTask<Void, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = ProgressDialog.show(Activity.this, "Image is Uploading", "Please Wait", false, false);
}
@Override
protected void onPostExecute(String string1) {
super.onPostExecute(string1);
progressDialog.dismiss();
Toast.makeText(EditPostActivity.this, string1, Toast.LENGTH_LONG).show();
}
@Override
protected String doInBackground(Void... params) {
ImageProcessClass imageProcessClass = new ImageProcessClass();
HashMap<String, String> HashMapParams = new HashMap<String, String>();
HashMapParams.put("pic", ConvertImage);
HashMapParams.put("filename", et_filename);
String FinalData = imageProcessClass.ImageHttpRequest(Api_Urls.UPDATE_EDIT_POST_DETAIL_URL, HashMapParams);
Log.d(TAG, "doInBackground: result: "+FinalData);
return FinalData;
}
}
AsyncTaskUploadClass AsyncTaskUploadClassOBJ = new AsyncTaskUploadClass();
AsyncTaskUploadClassOBJ.execute();
}
无法上传图片