[英]How do I upload a file(picture) from android and save to the blobstore using GAE and google endpoints?
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. 我有一个包含即时通讯的android应用。 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.
我的后端建立在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. 到目前为止,我已经研究了Google云存储,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.
在android中,我可以轻松完成http发布。 I'm just lost when it comes to doing this in endpoints
在端点上执行此操作时,我只是迷路了
I suggest the following approach to implement what you require: 我建议采用以下方法来实现您的要求:
如果您已经在使用端点,则可以按照@Romin的建议,将图像作为Base64发送,或者使用blobstore / GCS服务分两步上传图像,首先(通过端点)获取Upload URL,然后将图像发布到该端点URL。
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 (ie 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. 然后,使用端点,我将具有相同的链接键,并使用具有给定参数的服务处理程序来显示图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.