通过Node.js的上载的base64 EN $ C $光盘镜像到Amazon S3光盘镜像、Node、js、Amazon

2023-09-11 08:27:00 作者:拿命搏未来

昨天我做了深夜编码会议,并创建了一个小的Node.js / JS(当然实际的CoffeeScript,但CoffeeScript的是刚刚的JavaScript因此,可以说JS)应用程序。

yesterday i did a deep night coding session and created a small node.js/JS (well actually CoffeeScript, but CoffeeScript is just JavaScript so lets say JS) app.

什么是目标:​​

在客户端发送一个帆布datauri(PNG)到服务器(通过socket.io) 服务器上传图像到Amazon S3

第1步就完成了。

服务器现在有一个字符串一拉

the server now has a string a la

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACt...

我的问题是:?什么是我为流/上传这些数据到Amazon S3,并创建一个实际的图像有下一步

诺克斯 https://github.com/LearnBoost/knox 似乎是一个真棒LIB把东西S3,但我所缺少的是之间的粘合剂中的Base64恩codeD-图像串和实际行动的上传

knox https://github.com/LearnBoost/knox seems like an awesome lib to PUT something to S3, but what i'm missing is the glue between the base64-encoded-image-string and actual upload action?

任何想法,指针和反馈的欢迎。

any ideas, pointers and feedback welcome.

THX了很多,弗朗茨。

thx a lot, franz

推荐答案

确定,这个人就是答案how保存帆布数据文件

ok, this one is the answer how to save canvas data to file

基本上它洛斯像这样在我的code

basically it loos like this in my code

buf = new Buffer(data.dataurl.replace(/^data:image\/\w+;base64,/, ""),'base64')


req = knoxClient.put('/images/'+filename, {
             'Content-Length': buf.length,
             'Content-Type':'image/png'
  })

req.on('response', (res) ->
  if res.statusCode is 200
      console.log('saved to %s', req.url)
      socket.emit('upload success', imgurl: req.url)
  else
      console.log('error %d', req.statusCode)
  )

req.end(buf)
 
精彩推荐
图片推荐