Sorry if this is a little general. Hopfully I can get pointed in the correct direction.
对不起,如果这是一般的。我可以指出正确的方向。
I have an android app that includes instant messaging. I want to add the functionality to send photos in messages as well. My backend is built on GAE and cloud endpoints and is written in Java.
我有一个包含即时消息的Android应用程序。我想添加在消息中发送照片的功能。我的后端建立在GAE和云端点上,用Java编写。
So far, I've looked into google cloud storage, the blobstore, java servlet pages, etc. But a clear solution (or example using endpoints) has been impossible to find.
到目前为止,我已经研究过谷歌云存储,blobstore,java servlet页面等。但是一个明确的解决方案(或使用端点的例子)已经无法找到。
So, as the question states, how can I send and serve images from the blobstore using android and GAE endpoint backend?
因此,正如问题所述,我如何使用android和GAE端点后端从blobstore发送和提供图像?
Edit: This question is only regarding the back end. In android, I can do the http post easily enough. I'm just lost when it comes to doing this in endpoints
编辑:这个问题仅针对后端。在android中,我可以轻松地完成http帖子。在端点中执行此操作时,我只是迷失了方向
3 个解决方案
#1
0
Why not using a simple HTTP POST to handler for image upload?
为什么不使用简单的HTTP POST处理图像上传?
When I use the blobstore I typically have a pair of handlers one for uploading and one for serving images.
当我使用blobstore时,我通常有一对处理程序用于上载,一个用于提供图像。
So, in your case I'll rather do a post to a URL sending the image file and some parameter than can link it to the proper place in the datastore (i.e. user ID).
因此,在您的情况下,我宁愿对发送图像文件和某些参数的URL发布帖子,而不是将其链接到数据存储区中的适当位置(即用户ID)。
Then, using endpoints I'll have the same linking key and display the image using the serving handler with the given parameter.
然后,使用端点,我将使用相同的链接键,并使用具有给定参数的服务处理程序显示图像。
#2
1
I suggest the following approach to implement what you require:
我建议采用以下方法来实现您的需求:
- Pass the image data as base64 encoded text from your client.
- 将图像数据作为base64编码文本从客户端传递。
- On the server side, you can extract out the image content and then use one of many options that are available, which include Blobstore, Google Cloud Storage, etc. I suggest that you go with Google Cloud Storage because that is the recommended approach. If you prefer the Datastore, keep in mind that the data is limited to 1 MB in size, so you might hit that limit depending on the size of images that you are dealing with.
- 在服务器端,您可以提取图像内容,然后使用许多可用选项之一,其中包括Blobstore,Google Cloud Storage等。我建议您使用Google云端存储,因为这是推荐的方法。如果您更喜欢数据存储区,请记住数据的大小限制为1 MB,因此您可能会达到该限制,具体取决于您正在处理的图像大小。
- A SO question and answer here contains lot of relevant code that you could utilize: Sending images as a base64 string to a google cloud endpoint from cms
- 这里的SO问答包含许多您可以利用的相关代码:将图像作为base64字符串发送到来自cms的Google云端点
#3
0
If you are already using endpoints you can follow @Romin 's suggestion and send the images as Base64 or upload your images in 2 steps using the blobstore/GCS service, first get the Upload URL (via endpoints) and then post your image to that URL.
如果您已经在使用端点,可以按照@Romin的建议发送图像并将图像作为Base64发送,或者使用blobstore / GCS服务分两步上传图像,首先获取上传URL(通过端点),然后将图像发布到URL。
#1
0
Why not using a simple HTTP POST to handler for image upload?
为什么不使用简单的HTTP POST处理图像上传?
When I use the blobstore I typically have a pair of handlers one for uploading and one for serving images.
当我使用blobstore时,我通常有一对处理程序用于上载,一个用于提供图像。
So, in your case I'll rather do a post to a URL sending the image file and some parameter than can link it to the proper place in the datastore (i.e. user ID).
因此,在您的情况下,我宁愿对发送图像文件和某些参数的URL发布帖子,而不是将其链接到数据存储区中的适当位置(即用户ID)。
Then, using endpoints I'll have the same linking key and display the image using the serving handler with the given parameter.
然后,使用端点,我将使用相同的链接键,并使用具有给定参数的服务处理程序显示图像。
#2
1
I suggest the following approach to implement what you require:
我建议采用以下方法来实现您的需求:
- Pass the image data as base64 encoded text from your client.
- 将图像数据作为base64编码文本从客户端传递。
- On the server side, you can extract out the image content and then use one of many options that are available, which include Blobstore, Google Cloud Storage, etc. I suggest that you go with Google Cloud Storage because that is the recommended approach. If you prefer the Datastore, keep in mind that the data is limited to 1 MB in size, so you might hit that limit depending on the size of images that you are dealing with.
- 在服务器端,您可以提取图像内容,然后使用许多可用选项之一,其中包括Blobstore,Google Cloud Storage等。我建议您使用Google云端存储,因为这是推荐的方法。如果您更喜欢数据存储区,请记住数据的大小限制为1 MB,因此您可能会达到该限制,具体取决于您正在处理的图像大小。
- A SO question and answer here contains lot of relevant code that you could utilize: Sending images as a base64 string to a google cloud endpoint from cms
- 这里的SO问答包含许多您可以利用的相关代码:将图像作为base64字符串发送到来自cms的Google云端点
#3
0
If you are already using endpoints you can follow @Romin 's suggestion and send the images as Base64 or upload your images in 2 steps using the blobstore/GCS service, first get the Upload URL (via endpoints) and then post your image to that URL.
如果您已经在使用端点,可以按照@Romin的建议发送图像并将图像作为Base64发送,或者使用blobstore / GCS服务分两步上传图像,首先获取上传URL(通过端点),然后将图像发布到URL。