我将画布转换为数据 url 并将其发布到 GAE。该帖子在本地主机上工作,但在部署时返回 400。日志中没有错误,似乎该请求甚至没有发送到我的上传处理程序。
这是发布帖子的jquery代码
$('#submitButton').click(function() {
stage.toDataURL({
callback: function(dataUrl) {
$.ajax({
type: "POST",
url: "{{ upload_url|safe }}",
data: {file: dataUrl}
}).done(function( respond ) {
alert(respond);
});
}
});
});
这是处理帖子的python代码
类 UploadHandler(blobstore_handlers.BlobstoreUploadHandler): def post(self): logging.info('uploading image') self.response.headers["Access-Control-Allow-Origin"] = "*"
try:
data = self.request.get('file')
data_to_64 = re.search(r'base64,(.*)', data).group(1)
decoded = data_to_64.decode('base64')
logging.info('Create the file')
file_name = files.blobstore.create(mime_type='image/png')
logging.info('Open the file and write to it')
with files.open(file_name, 'a') as f:
f.write(decoded)
logging.info('Finalize the file. Do this before attempting to read it.')
files.finalize(file_name)
key = files.blobstore.get_blob_key(file_name)
url = '/serve/%s' % key
self.response.out.write('{ "url": "' + url + '" }')
except Exception, e:
logging.error(e)
任何想法出了什么问题?