Enable CORS in google app engine blobstore downloader

I use "send_blob" to download a pdf file using a blobstore device. How can I enable CORS for this? I tried to add

self.response.headers.add_header("Access-Control-Allow-Origin", "*") 

to the function in which I call send_blob, but it does not work.

+4
source share
2 answers

Found solution in

http://enable-cors.org/server_appengine.html

Added a base handler for the blobstore loader.

+2
source

CORS on the App Engine For Python-based applications on the Google App Engine, you can use the self.response.headers.add_header () method, for example:

 class CORSEnabledHandler(webapp.RequestHandler): def get(self): self.response.headers.add_header("Access-Control-Allow-Origin", "*") self.response.headers['Content-Type'] = 'text/csv' self.response.out.write(self.dump_csv()) 

For Java applications, use resp.addHeader ():

 public void doGet(HttpServletRequest req, HttpServletResponse resp) { resp.addHeader("Access-Control-Allow-Origin", "*"); resp.addHeader("Content-Type", "text/csv"); resp.getWriter().append(csvString); } 

And for Go-based applications, use w.Header (). Add ():

 func doGet(w http.ResponseWriter, r *http.Request) { w.Header().Add("Access-Control-Allow-Origin", "*") w.Header().Add("Content-Type", "text/csv") fmt.Fprintf(w, csvData) } 
+2
source

Source: https://habr.com/ru/post/1498162/


All Articles