2

我可以使用 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");

}

在此先感谢您的帮助。

4

1 回答 1

0

您可以将android中的“imageField”键替换为电子邮件地址。

在服务器端,从 get 上传方法中获取所有密钥。

Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
 Iterator<String> iter = blobs.keySet().iterator();
    while (iter.hasNext()) {
        String key = iter.next(); // your email
}
于 2013-11-27T16:14:29.367 回答