2013-04-01 118 views
1

得到這個工作,我不知道是否是最好的方法:filepicker.io - 畫布保存爲PNG

// Take off the "data:image/png;base64," prefix 
var b64 = canvas.toDataURL().split(',', 2)[1]; 
filepicker.store(
    b64, 
    { 
    mimetype: 'image/png', 
    base64decode: true 
    } 
... 

回答

1

是啊,對我來說很好!您可能想要用稍微更精確的正則表達式解析b64數據,但base64編碼的數據不應該包含逗號,所以一般來說應該沒問題。作爲最小,您可以指定.split(',', 2)

+0

我會補充說。 思想:如果你接受了完整的data:URL,那麼我們就不需要了'MIME類型:「圖像/ PNG」,base64decode:TRUE' – forresto

+0

想這可能節省一些帶寬與'window.atob發送二進制數據( canvas.toDataURL()。split(',',2)[1])'和'base64decode:false'。它返回OK,但是[損壞](https://www.filepicker.io/api/file/BFsTLioTAS3lmuSUigu3)。 – forresto