gpt4 book ai didi

Android 和 Google-app-engine createuploadURL - 如何传递附加参数(即电子邮件地址)

转载 作者:行者123 更新时间:2023-11-29 13:59:03 24 4
gpt4 key购买 nike

我能够使用 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中的“imageField”键替换为邮箱地址。

在服务器端,通过 get upload 方法获取所有 key 。

Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
Iterator<String> iter = blobs.keySet().iterator();
while (iter.hasNext()) {
String key = iter.next(); // your email
}

关于Android 和 Google-app-engine createuploadURL - 如何传递附加参数(即电子邮件地址),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10521849/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com