Enable CORS in google app engine blobstore downloa

2019-06-26 17:41发布

I am using "send_blob" to download pdf from google app engine blobstore. How can i enable CORS for this?I have tried adding

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

to the function where i call send_blob but it is not working.

2条回答
啃猪蹄的小仙女
2楼-- · 2019-06-26 18:14

CORS on App Engine For Python-based applications in Google App Engine, the self.response.headers.add_header() method can be used, such as:

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-based 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)
}
查看更多
聊天终结者
3楼-- · 2019-06-26 18:24

Found the solution in

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

Added a basehandler for blobstore download handler.

查看更多
登录 后发表回答