Google App Engine serve Content-Length header

2019-06-16 06:07发布

问题:

I'm using the following to serve a file from GS through PHP App Engine:

google\appengine\api\cloud_storage\CloudStorageTools::serve

This doesn't set the Content-Length header and App Engine doesn't allow that header to be set manually by a script. (https://cloud.google.com/appengine/docs/python/how-requests-are-handled#headers_removed)

How can I set the Content-Length header so the user has an idea of how large the file is when they start to download it?

回答1:

I have experience with App Engine but used with Python, but I hope this is useful.

App Engine will remove the Content-Length header if you set it manually, but it will automatically set it before the response is sent to the client.

This ensures there are no mistakes on the value and it will be the length of the absolute final response sent by App Engine.

I have tested this with a new simple app by setting a wrong size manually, leaving it blank and setting the correct size. In all three tests, the correct Content-Length is returned to the client by App Engine.

Have you tested from the client to see if the header is present and correct?

I hope this helps clarify that while App Engine will remove the header if you set it, it will set it to the correct value automatically.



回答2:

If you use the script provided by google gsutil and run "du" command you should be able to get that data. Also you have some interesting examples of the API's functionality here and how install gsutil here.

Regards