[英]How to upload canvas data uri to amazon s3 server
Right now, I've passed the canvas data URI string 现在,我已经传递了画布数据URI字符串
(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAADwCAYAAABxLb1rAAAgAElEQVR..... )
(数据:image / png; base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAADwCAYAAABxLb1rAAAgAElEQVR .....)
to my hapi (NodeJS) server. 到我的hapi(NodeJS)服务器。
My question is: 我的问题是:
What are my next steps to "stream"/upload this data to Amazon S3 and create an actual image there? 我将接下来的步骤“流”/上传到Amazon S3并在那里创建实际图像是什么?
before send object to s3 you must transform base64 to buffer and after send, for example: 在将对象发送到s3之前,必须将base64转换为缓冲区并在发送之后,例如:
var buf = new Buffer(b64string, 'base64');
s3.putObject({/*some params*/, Body: buf}, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
After this you send data to s3 and you will can open image without decode. 在此之后,您将数据发送到s3,您将无需解码即可打开图像。
Good luck! 祝好运!
Pass that string to in body of S3 upload function 将该字符串传递给S3上传功能的 主体
var myDataUri = "data:application/pdf;base64,JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYW..." var myFile=dataURItoBlob(myDataUri); function dataURItoBlob(dataURI) { console.log('1: ',dataURI); var binary = atob(dataURI.split(',')[1]); var array = []; console.log('2: ',binary.length); for (var i = 0; i < binary.length; i++) { array.push(binary.charCodeAt(i)); } return new Blob([new Uint8Array(array)], { type: 'application/pdf' }); } if (myFile)) { results.innerHTML = ''; var params = { Key: new Date().getTime() + '.pdf', ContentType: 'application/pdf', Body: myFile }; bucket.upload(params, function(err, data) { results.innerHTML = err ? 'ERROR!' : 'UPLOADED.: ' + file; }); } else { results.innerHTML = 'Nothing to upload.'; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.