我有将图像上传到服务器的代码,它可以工作,
HttpEntity resEntity;
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(Constants.url_create_product);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
File file= new File(path);
FileBody bin = new FileBody(file);
reqEntity.addPart("phone", new StringBody(mPhoneNumber));
reqEntity.addPart("prod_title", new StringBody(namapro));
reqEntity.addPart("prod_price", new StringBody(hargapro));
reqEntity.addPart("prod_desc", new StringBody(despro));
reqEntity.addPart("prod_order", new StringBody(orderpro));
reqEntity.addPart("prod_image", bin);
post.setEntity(reqEntity);
HttpResponse response = httpClient.execute(post);
resEntity = response.getEntity();
String response_str = EntityUtils.toString(resEntity);
Gson gson = new Gson();
gson.toJson(response_str);
if (resEntity != null) {
Log.i("RESPONSE",response_str);
runOnUiThread(new Runnable(){
public void run() {
try {
Toast.makeText(getApplicationContext(),"Upload Complete. Check the server uploads directory.", Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
但我有菜单图像编辑器。该编辑器是裁剪图像,那是代码返回位图值,如下所示
Bundle extras = data.getExtras();
if (extras != null) {
photo = extras.getParcelable("data");
mImageView.setImageBitmap(photo);
}
File f = new File(mImageCaptureUri.getPath());
if (f.exists()) f.delete();
break;
我想问一下,如何使用参数位图将图像发送到服务器。如您所知,我发送图像的代码现在使用参数路径(字符串)。