简体   繁体   English

将图像/视频从Android / iOS发送到Google Cloud Endpoints

[英]Send Images/Videos from Android/iOS to Google Cloud Endpoints

I'm really needing your help/suggestion/clue/etc. 我真的需要您的帮助/建议/线索/等。 I'm developing an application for Android and iOS which will allow the user to upload pictures and videos. 我正在开发适用于Android和iOS的应用程序,它将允许用户上传图片和视频。

What I'm trying to do: 我正在尝试做的是:

1 - Android/iOS send picture/video to my Google Cloud Endpoint; 1-Android / iOS将图片/视频发送到我的Google Cloud Endpoint;

2 - Google Cloud Endpoint upload the image/video to Google Cloud Storage; 2-Google Cloud Endpoint将图像/视频上传到Google Cloud Storage; (Works) (作品)

3 - Google Cloud Endpoint retrieve the servingURL from Google Cloud Storage and send back to Android/iOS; 3-Google Cloud Endpoint从Google Cloud Storage检索服务URL并发送回Android / iOS; (Works) (作品)

4 - Android/iOS stream the picture/video by its URL. 4-Android / iOS通过其URL传输图片/视频。 (Works) (作品)

So the problem is just the first step, send the image/video to Google Cloud Endpoint. 因此,问题只是第一步,将图像/视频发送到Google Cloud Endpoint。

I'm reading a lot, searching, researching and didn't figured out how to do it. 我正在阅读很多东西,正在搜索,研究并且没有弄清楚该怎么做。

Please, ANY suggestion will be appreciate. 请,任何建议将不胜感激。 I'm open to new ideas about the way to implement this feature as well. 我也对实现此功能的方式持开放态度。 Thank you guys! 感谢大伙们!

.

- - - - - - - - - - - - - - - - - - - - -- - - - - - - - UPDATE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ---------------------------更新-------------------------- ---------------

.

After research a bit more I noticed the better way to do it would be uploading straight from Android/iOS. 经过更多研究后,我注意到更好的方法是直接从Android / iOS上传。 I figured out how to do it but now I got stuck about how to implement the servlet to get called automatically after the client upload the file using the urlUpload generated by my endpoint. 我想出了解决方法,但是现在我陷入了困境,即如何在客户端使用由端点生成的urlUpload上传文件后自动实现servlet的调用。

So far I did: 到目前为止,我做到了:

1 - Client request my Google Endpoint to retrieve URL for upload; 1-客户要求我的Google Endpoint检索要上传的URL;

2 - Google Endpoint generates '/upload' url using with this code: 2-Google Endpoint使用以下代码生成“ / upload”网址:

BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
UploadOptions uploadOptions = UploadOptions.Builder.withGoogleStorageBucketName(ConstUtil.storage.BUCKET_NAME);

String uploadUrl = blobstoreService.createUploadUrl("/upload", uploadOptions);

response.setSimpleString(uploadUrl);
response.setCode(MWCode.SUCCESS.getCode());
response.setMessage(MWCode.SUCCESS.getMessage());

return response;

3 - Client (Android/iOS) receive this url and upload the file (I didn't implement it yet but I saw many clean example and looks very easy to understand) 3-客户端(Android / iOS)接收此URL并上传文件(我尚未实现它,但是我看到了很多干净的示例,并且看起来很容易理解)

4 - Blobstore service fire Google Endpoint as callback sending keys of the uploaded object 4-Blobstore服务将Google Endpoint触发为上载对象的回调发送键

5 - I use Blob keys to retrieve servingURL to serve the files with clients (Android/iOS) (already implemented) 5-我使用Blob键检索serveURL,以将文件提供给客户端(Android / iOS)(已实现)

I have no idea about how to implement the step 4 once all tutorials and examples I see are not using Google Cloud Endpoints. 一旦我看到的所有教程和示例都没有使用Google Cloud Endpoints,我就不知道如何实施第4步。 Please, does anyone can give me the path/link/code or clue of how I could implement it? 拜托,有人能给我实现该方法的路径/链接/代码或线索吗?

If you're using the Endpoints frameworks, this is pretty hard to do. 如果您使用的是Endpoints框架,则很难做到。 For single images, you can base64 encode them, but that's not very efficient. 对于单个图像,您可以对它们进行base64编码,但这不是很有效。 It probably works better for your client to interact directly with GCS and use a signed URL for upload. 让您的客户直接与GCS互动并使用签名的URL进行上传可能会更好。

As Saiyr suggested, you should upload directly to the Cloud Storage from the Android application (without going through Endpoints). 正如Saiyr所建议的那样,您应该直接从Android应用程序上传到Cloud Storage(不要通过Endpoints)。 See Uploading image from Android to GCS and upload image to google cloud storage with an application android . 请参阅使用Android将图像从Android 上传 到GCS 并将图像上传到Google云存储

Since you know the bucket and file name, the URL of the uploaded file is easily deductible, see the following documentation to decide which URL to use (depending on whether the user shall be authenticated or not, see Section "A user is granted read access to an object") https://cloud.google.com/storage/docs/cloud-console#_accessing 由于您知道存储桶和文件名,因此可以轻松扣除上载文件的URL,请参阅以下文档来确定要使用的URL(取决于是否对用户进行身份验证,请参阅“授予用户读取权限”部分到对象”) https://cloud.google.com/storage/docs/cloud-console#_accessing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM