我試圖通過使用畫布從視頻創建圖像,然後將圖像發送到API。JavaScript:將base64解碼爲二進制數據
這是我的代碼(大部分爲簡潔起見省略了)
var image = new Image();
image.src = canvas.toDataURL("image/png");
var newFile = new File([atob(image.src)], lorem.png, {
type: "image/png",
lastModified: Date.now()
})
image.src是一個長的字符串,這似乎是在格式BASE64數據:圖像/ PNG; BASE64
[鏈接到數據] [1]:https://gist.github.com/anonymous/d357e780fa60b2c47490a9f795e34acf
當我嘗試將數據與功能ATOB,我收到以下錯誤解碼成二進制:
Error: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
我不清楚base64數據的哪一部分沒有正確格式化。