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);
次に、サーブレット コードで、電子メール パラメータを取得しようとします。
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");
}
助けてくれてありがとう。