我可以使用 createuploadurl 成功存储位图图像。我的问题是我想传入一个电子邮件地址参数也将图像发送到之后。
这是我尝试使用的代码:
//Code for uploading image within android
//Now upload the image
ByteArrayOutputStream bao = new ByteArrayOutputStream();
mBitmap.compress(Bitmap.CompressFormat.JPEG, 90, bao);
HttpPost httppost = new HttpPost(url);
HttpParams postParams = new BasicHttpParams();
postParams.setParameter( "email", "someone@gmail.com" );
httppost.setParams(postParams);
MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );
byte [] ba = bao.toByteArray();
entity.addPart("imageField", new ByteArrayBody(ba, "myimage.jpg"));
httppost.setEntity(entity);
// Execute HTTP Post Request
response = httpclient.execute(httppost);
然后,在 servlet 代码中,我尝试获取电子邮件参数:
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
//this comes up as null
if (req.getParameter("email") != null) {
this.email = req.getParameter(email);
}
Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
BlobKey blobKey = blobs.get("imageField");
resp.setContentType("text/plain");
}
在此先感谢您的帮助。