9

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?

2 Answers 2

5
+25

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.

7
  • Thanks the reply. I'm using PHP App Engine, the Content Length header is correct for every request, except when using google\appengine\api\cloud_storage\CloudStorageTools::serve. It is omitted. Is this a bug with the PHP version?
    – Adam
    Nov 14, 2016 at 15:46
  • I went on to read the specific documentation for the serve method. The signature reads serve(string $gs_filename, array<mixed,mixed> $options = array()). I can see that on the options you can provide start, end and use_range to change the served range of the file. Are you sending any options?
    – Zebs
    Nov 16, 2016 at 16:46
  • No, I'm only sending the filename
    – Adam
    Nov 16, 2016 at 19:34
  • I discovered a HEAD request does return the proper Content-Length header, but omitted in a GET.
    – Adam
    Nov 16, 2016 at 21:23
  • With such a specific behaviour I would file a bug report. Is this happening with all your files or just some files?
    – Zebs
    Nov 17, 2016 at 19:39
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.