如何使用Java将图像/视频上传到Google云端存储

时间:2020-12-20 20:18:37

I'm developing a server in Java which will provide URLs for images that clients uploaded. Basically the Android/iOS will send some kind of data (I still don't know which data would be sent for image and videos) then I'll upload those images/videos to Google Storage and provide URLs which the users (Android/iOS) will be able to stream.

我正在开发一个Java服务器,它将为客户上传的图像提供URL。基本上Android / iOS会发送某种数据(我仍然不知道会为图像和视频发送哪些数据)然后我会将这些图像/视频上传到Google存储并提供用户的URL(Android / iOS) )将能够流。

I've just started with Google Storage and I can't find any example of how to upload an image using Java. All examples I found or are deprecated or it's in PHP or it's not clean.

我刚刚开始使用Google Storage,但我找不到任何使用Java上传图像的示例。我发现或弃用的所有示例或者它都是PHP或者它不干净。

I think I will need to use the JSON client Library but I can't find a good example for this library either.

我想我需要使用JSON客户端库,但我也找不到这个库的好例子。

Please any help will be VERY appreciate.

请任何帮助将非常感谢。

1 个解决方案

#1


1  

Based on your answer to my comment above, you could use the method I described in the following Stack Overflow response in order to save the file from your servlet to the Datastore and return the URL:

根据您对上述评论的回答,您可以使用我在以下Stack Overflow响应中描述的方法,以便将文件从servlet保存到数据存储区并返回URL:

How to return a file with Google Cloud Endpoints?.

如何使用Google Cloud Endpoints返回文件?

The two differences between your requirements and the method described in this response are:

您的要求与此回复中描述的方法之间的两个差异是:

  • The way the file is created: in your case through a file input stream, as you mentionned
  • 创建文件的方式:在您的情况下,通过文件输入流,如您所提到的

  • The way you return the URL: since you will probably not use Google Endpoints (because of file input stream) you don't need to return the URL in a string wrapper.
  • 返回URL的方式:由于您可能不会使用Google端点(因为文件输入流),因此您无需在字符串包装器中返回URL。

#1


1  

Based on your answer to my comment above, you could use the method I described in the following Stack Overflow response in order to save the file from your servlet to the Datastore and return the URL:

根据您对上述评论的回答,您可以使用我在以下Stack Overflow响应中描述的方法,以便将文件从servlet保存到数据存储区并返回URL:

How to return a file with Google Cloud Endpoints?.

如何使用Google Cloud Endpoints返回文件?

The two differences between your requirements and the method described in this response are:

您的要求与此回复中描述的方法之间的两个差异是:

  • The way the file is created: in your case through a file input stream, as you mentionned
  • 创建文件的方式:在您的情况下,通过文件输入流,如您所提到的

  • The way you return the URL: since you will probably not use Google Endpoints (because of file input stream) you don't need to return the URL in a string wrapper.
  • 返回URL的方式:由于您可能不会使用Google端点(因为文件输入流),因此您无需在字符串包装器中返回URL。