让两台服务器相互通信

时间:2022-01-31 13:02:27

I have application written in GWT and hosted on Google AppEngine/Java. In this application user will have an option to upload video/audio/text file to the server. Those files could be big, up to 1gb or so and because GAE/J does not support large file I have to use another server to store those files. This would be easy to implement if there was no cross-domain security feature in browsers. So, what I'm thinking is to make GAE Server talk to my server (Glassfish or any other java servers if needed) to tell url to the file and if possible send status of uploaded file (how many percent was uploaded) so I can show status on clients screen. Here is what I'm thinking to do.

我有用GWT编写的应用程序,并托管在Google AppEngine / Java上。在此应用程序中,用户可以选择将视频/音频/文本文件上载到服务器。这些文件可能很大,高达1GB左右,因为GAE / J不支持大文件,我必须使用另一台服务器来存储这些文件。如果浏览器中没有跨域安全功能,这将很容易实现。所以,我在想的是让GAE服务器与我的服务器(Glassfish或任何其他java服务器,如果需要)通话,告诉url文件,如果可能的话,发送上传文件的状态(上传了多少百分比),这样我就可以在客户端屏幕上显示状态。这是我正在考虑的事情。

When user loads GWT page that is stored on GAE/J he/she will upload file to my server, then my server will send response back to GAE and GAE will send response to the client. If this scenario is possible what would be the best way to implement GAE to Glassfish conversation?

当用户加载存储在GAE / J上的GWT页面时,他/她将文件上传到我的服务器,然后我的服务器将响应发送回GAE,GAE将向客户端发送响应。如果这种情况可能,那么实施GAE到Glassfish对话的最佳方式是什么?

3 个解决方案

#1


Actually before that maybe you can try using first approach via by-passing cross-domain security of browsers using iframe. There are some ready to use components for this but for your problem which of them can be usable I don't know. Just google for these components...

实际上在此之前,您可以尝试使用第一种方法,通过使用iframe绕过浏览器的跨域安全性。有一些准备使用的组件,但对于你的问题,哪些是可用的,我不知道。只是谷歌这些组件......

#2


Doing it the original way you suggested use URL Fetch Service The down side to doing it the other way is that you introduce dependencies on multiple sites inside your web pages.
The downside of using the URL Fetch Service is that you have to pay by number of bytes transferred after you have reached the free quota.

按照您建议的原始方式使用URL提取服务这样做的另一方面是您在网页内的多个网站上引入依赖关系。使用URL提取服务的缺点是,您必须按照达到免费配额后转移的字节数进行支付。

#3


One option would be to wait - the blobstore limit won't always be 50MB!

一种选择是等待 - blobstore限制不会总是50MB!

If you're in a hurry, though, I would suggest an approach like the following:

但是,如果你赶时间,我建议采用如下方法:

  1. Have your App Engine app generate a signed token that signifies the user has permission to upload a file. The token should include the current date and time, the user's user ID, the maximum file size, and any other relevant information, and should be signed using HMAC-SHA1 with a secret key that your App Engine app and your server both know.
  2. 让您的App Engine应用生成一个签名令牌,表示用户有权上传文件。令牌应包括当前日期和时间,用户的用户ID,最大文件大小以及任何其他相关信息,并且应使用HMAC-SHA1使用您的App Engine应用程序和服务器都知道的密钥进行签名。

  3. Return a form to the user that POSTs to a URL on your blob hosting server, and embeds the token you generated in step 1. If you want progress notifications, you can use a tool like plupload, and serve the form in an IFrame served by your upload server.
  4. 将表单返回给发布到Blob托管服务器上的URL的用户,并嵌入您在步骤1中生成的令牌。如果您想要进度通知,可以使用plupload等工具,并在服务的IFrame中提供表单。你的上传服务器。

  5. When the user uploads the file to your server, the server should return a redirect back to your App Engine app, with a new token embedded in the redirect URL. That token, again signed with a common secret, contains the ID of the newly uploaded file.
  6. 当用户将文件上传到您的服务器时,服务器应该将重定向返回到App Engine应用程序,并在重定向URL中嵌入新的令牌。该令牌再次使用共同密钥签名,包含新上载文件的ID。

  7. When your App Engine app receives a request for the redirect URL, it knows the upload was completed, and can record the new file's ID etc in the datastore.
  8. 当您的App Engine应用程序收到重定向URL请求时,它知道上载已完成,并且可以在数据存储区中记录新文件的ID等。

Alternately, you can use Amazon's S3, which already supports all this with its HTML Form support.

或者,您可以使用Amazon的S3,它已经通过HTML表单支持支持所有这些。

#1


Actually before that maybe you can try using first approach via by-passing cross-domain security of browsers using iframe. There are some ready to use components for this but for your problem which of them can be usable I don't know. Just google for these components...

实际上在此之前,您可以尝试使用第一种方法,通过使用iframe绕过浏览器的跨域安全性。有一些准备使用的组件,但对于你的问题,哪些是可用的,我不知道。只是谷歌这些组件......

#2


Doing it the original way you suggested use URL Fetch Service The down side to doing it the other way is that you introduce dependencies on multiple sites inside your web pages.
The downside of using the URL Fetch Service is that you have to pay by number of bytes transferred after you have reached the free quota.

按照您建议的原始方式使用URL提取服务这样做的另一方面是您在网页内的多个网站上引入依赖关系。使用URL提取服务的缺点是,您必须按照达到免费配额后转移的字节数进行支付。

#3


One option would be to wait - the blobstore limit won't always be 50MB!

一种选择是等待 - blobstore限制不会总是50MB!

If you're in a hurry, though, I would suggest an approach like the following:

但是,如果你赶时间,我建议采用如下方法:

  1. Have your App Engine app generate a signed token that signifies the user has permission to upload a file. The token should include the current date and time, the user's user ID, the maximum file size, and any other relevant information, and should be signed using HMAC-SHA1 with a secret key that your App Engine app and your server both know.
  2. 让您的App Engine应用生成一个签名令牌,表示用户有权上传文件。令牌应包括当前日期和时间,用户的用户ID,最大文件大小以及任何其他相关信息,并且应使用HMAC-SHA1使用您的App Engine应用程序和服务器都知道的密钥进行签名。

  3. Return a form to the user that POSTs to a URL on your blob hosting server, and embeds the token you generated in step 1. If you want progress notifications, you can use a tool like plupload, and serve the form in an IFrame served by your upload server.
  4. 将表单返回给发布到Blob托管服务器上的URL的用户,并嵌入您在步骤1中生成的令牌。如果您想要进度通知,可以使用plupload等工具,并在服务的IFrame中提供表单。你的上传服务器。

  5. When the user uploads the file to your server, the server should return a redirect back to your App Engine app, with a new token embedded in the redirect URL. That token, again signed with a common secret, contains the ID of the newly uploaded file.
  6. 当用户将文件上传到您的服务器时,服务器应该将重定向返回到App Engine应用程序,并在重定向URL中嵌入新的令牌。该令牌再次使用共同密钥签名,包含新上载文件的ID。

  7. When your App Engine app receives a request for the redirect URL, it knows the upload was completed, and can record the new file's ID etc in the datastore.
  8. 当您的App Engine应用程序收到重定向URL请求时,它知道上载已完成,并且可以在数据存储区中记录新文件的ID等。

Alternately, you can use Amazon's S3, which already supports all this with its HTML Form support.

或者,您可以使用Amazon的S3,它已经通过HTML表单支持支持所有这些。