javascript - CORS issue with aws-sdk S3 on Firefox -
o/s: mac os sierra 10.12.16 browser: firefox 54.0.1
i have bug firefox javascript site when uploading pdfs s3 using aws-sdk node. works on chrome, ie11 , safari.
update:
it seems work ok when upload pdf's under 500kb. when upload files on 500kb works 1 time out of 10.
i signed request pdf by:
client:
$.ajax({ cache: false, type: 'get', mimetype: 'text/plain', url: '/gets3url?file-name=' + annexurefilename + '&file-type=' + validatedfile.type + '&url-folder=' + index.s3urlfolder, success: function (data, textstatus, request) { const response = json.parse(data); putlocalfiles(validatedfile, reference, response.signedrequest, annexurefilename, response.url, callback); }, error: function (err, textstatus, request) { _errorcallback(err.responsetext); } });
server:
exports.gets3url = (req, res) => { const filename = req.query['file-name']; const foldername = req.query['url-folder']; const filetype = req.query['file-type']; const folderandfile = foldername + '/' + filename; const s3params = { bucket: s3_bucket, key: folderandfile, contenttype: filetype, acl: 'public-read' }; s3.getsignedurl('putobject', s3params, (error, data) => { if (error) { console.error(error); return res.status(500).send(error); } const returndata = { signedrequest: data, url: `https://${s3_bucket}.s3.amazonaws.com/${filename}` }; res.write(json.stringify(returndata)); res.end(); }); };
when try 'put' these files s3:
// https://gist.github.com/guumaster/9f18204aca2bd6c71a24 $.ajax({ type: 'put', url: signedrequest, // content type must parameter signed url contenttype: file.type, // flag important, if not set, try send data form processdata: false, // actual file sent raw data: file, success: function (data, textstatus, request) { addtosupportingdocsurldo(annexurefilename, reference, url, callback); }, error: function (err, textstatus, request) { _errorcallback('could not upload file: ' + url + ' error: ' + err.responsetext); // todo: send support@judgeit.com.au email error } });
the bug gets returned is:
cross-origin request blocked: same origin policy disallows reading remote resource @ https://s3bucket.s3-ap-southeast-2.amazonaws.com/596772d37d3e5f6170d51de9/599be64abbebb505d93f0327/annexure-1.pdf?awsaccesskeyid=awsaccesskey&content-type=application%2fpdf&expires=1503390725&signature=signatureu%3d&x-amz-acl=public-read. (reason: cors header ‘access-control-allow-origin’ missing).
wiki
Comments
Post a Comment