How to upload base64 encoded image data to S3 using JavaScript only?

前端 未结 4 1780
花落未央
花落未央 2021-01-30 18:43

I have a rails app on Heroku (cedar env). It has a page where I render the canvas data into an image using toDataURL() method. I\'m trying to upload the returned ba

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-30 19:22

    If anyone cares: here is the coffescript version of the function given above!

      convertToBlob = (base64) ->
        binary = atob base64.split(',')[1]
        array = []
        for i in [0...binary.length]
          array.push binary.charCodeAt i
        new Blob [new Uint8Array array], {type: 'image/jpeg'}
    

提交回复
热议问题