【问题标题】:Android and Google-app-engine createuploadURL - how to pass additional parameters (i.e. email address)Android 和 Google-app-engine createuploadURL - 如何传递附加参数(即电子邮件地址)
【发布时间】:2012-05-18 07:23:58
【问题描述】:

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

}

提前感谢您的帮助。

【问题讨论】:

    标签: android google-app-engine parameter-passing image-uploading blobstore


    【解决方案1】:

    您可以将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
    }
    

    【讨论】:

      猜你喜欢
      • 2010-12-22
      • 2011-03-21
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2012-07-26
      • 1970-01-01
      • 1970-01-01
      • 2010-10-27
      相关资源
      最近更新 更多