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);

次に、サーブレット コードで、電子メール パラメータを取得しようとします。

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 upload メソッドからすべてのキーを取得します。

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 に答える