0

I would like to handle large file uploads to App Engine (Blobstore -> Google Cloud Storage) in my AJAX focused webapp hosted on the same App Engine domain.

From the browser javascript client I call the App Engine server and receive a URL in response (created from 'create_upload_url') but I am stuck with how to take my file and upload it to that URL without getting a cross domain error. I appear to be unable to set CORS headers on the Blobstore receiver and the domain doesn't match the domain my app is serving from ('create_upload_url' appends '1-dot-' to the prefix of the subdomain).

Have any ideas or experience with this?

One idea: since "1-dot-" prefix seems to be just referring to a particular deployed version, perhaps if I parse the url and remove any prefix like that to make the domains the same and submit to that url to avoid a domain mis-match.

Ryan Bavetta
  • 865
  • 8
  • 21
  • Are you serving off of a custom domain or appspot? Create upload url does not seem to add the version prefix (try it here http://shell-27.appspot.com/). Are you sure you are not talking to a specific version from your javascript? On a side note, when creating the upload url you can specify the Cloud Storage bucket. – Sebastian Kreft Jun 19 '13 at 16:37
  • Yes, I'm serving off appspot. You are right, on that shell the exact same command does not prepend the '1-dot-' (but it still does on my instance). Here is the command I am using: blobstore.create_upload_url("/image/upload/", max_bytes_per_blob=100000000, max_bytes_total=100000000, rpc=None, gs_bucket_name="bucketname") – Ryan Bavetta Jun 19 '13 at 17:29
  • I am calling 'create_upload_url' from within a Cloud Endpoints script, perhaps that is the problem? – Ryan Bavetta Jun 19 '13 at 17:33

2 Answers2

1

Thanks for bringing this up. This is due to the current nature of request handling and we are considering it a bug while brainstorming to figure out the best way forward.

Currently, if a user makes a request to

https://myappid.appspot.com/_ah/api/myApi/v1/methodpath

then it is routed by Google's API Infrastructure to

https://version-dot-myappid.appspot.com/_ah/spi/MyApi.Method

where version is the default version for the myappid application.

UPDATE: A previously suggested workaround a la How do I parse a URL into hostname and path in javascript? has been shown not to work. This is because the App Engine instance that calls create_upload_url "knows" which version/host it is and so changing this causes errors.

Community
  • 1
  • 1
bossylobster
  • 9,993
  • 1
  • 42
  • 61
  • bossylobster, modifying the upload URL does not work. I have modified a working example (that normally uses the "version-dot-" as-is) and I have confirmed the URL has transformed correctly, and it does not work as well. I get a 303 redirect to http://temporary-blobstore-error.appspot.com/ Also, there is no entry or error recorded in the App Engine Logs. – Ryan Bavetta Jun 20 '13 at 02:20
  • Ahh, you're right, my bad with the erroneous recommendation. It seems it is "broken" for now. We have a bug filed internally for tracking this and will do our best to get it patched. Updated my answer to reflect this. – bossylobster Jun 20 '13 at 02:22
  • Is this the bug you referred to? https://code.google.com/p/googleappengine/issues/detail?id=5059 – Zach Young Jul 30 '15 at 23:28
1

In my program this problem happen only under some circumstances, and only on line, not in the dev server. I got the origin of the problem, but is a bug o the appengine

In the javascript of the page i have:

$.ajax({
          type: "POST",
          url: upload_url,
          data: formData,
          contentType: false,
          processData: false
            })....

I get upload_url in python code from: upload_url = blobstore.create_upload_url('/uploadDragImage')

when i call that page: https://comunapp-dot-skilled-999.appspot.com/item?categ=news

the ajax call works perfectly, but if I add a parameter:

https://comunapp-dot-skilled-999.appspot.com/item?categ=news&pippo

the generated upload_url seems to be meaningless , the ajax call get this error:

Mixed Content: The page at 'https://comunapp-dot-skilled-999.appspot.com/item?categ=news&luca' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://temporary-blobstore-error.appspot.com/'. This request has been blocked; the content must be served over HTTPS.

The '&' in the url of the page break the generation of the url : blobstore.create_upload_url('/uploadDragImage')

Note: the dev server works, the proble is only on line

A possible solution is to avoid using &, and use something else to separate parameters

chairam
  • 335
  • 5
  • 12