我想知道如何转换base64数据,例如
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAAAXNSR0IArs4c6QAAAZhJREFUOBGVk79Lw1AQx+9eU5zcC40u4iLYtBQcpaN0dXBxLeIP6CBugiAIIiooooi4ufgPdC6OYm3TwUVcNIVKR+kgTXPehUZt01TfQZJ33+/nvk2TF4ReUS5n2HcvRUTKA0GagD4AsaoArlJdpyRYPWbmPYACEGUQcBwQakRYsuanTrBcdoVBOT2NmdOdDt0SQEb6UCHe+BrRcshjgUOq8TguzXw6z0jZbNyuNu9ZTw+DNbSalUnMxRbfY1t8Z0N/WSNM0ESr2W4rD2FBczASlywlLyCS0DU4i18itHTnRvAtxdvkcQSgZXFWRXEd8pS/h7Smw7DLWUdqtvP2AAr2w76mwhmSJc8QrO3CDiJea0Z84zIrGSL4X4osiL8h25i8APJWpP93obq03NdVDuXt/CtQGgmtG+YZEaxJ/1chwnnKdTaCMOH9vxwMimF1G+uo8DTQoq7C+GzvzgKuLzAQLdcpKgXHQT94FU+YQV36oYFipNzGJig8kHVfseZ7faJGYxsTezWVJDlkrTEajdaN5K4c0cSP8wV8eoEZjT4J3gAAAABJRU5ErkJggg==
到PNG图像(testing.png
)。
并像这样保存
var imageS = new Image();
imageS.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAAAXNSR0IArs4c6QAAAZhJREFUOBGVk79Lw1AQx+9eU5zcC40u4iLYtBQcpaN0dXBxLeIP6CBugiAIIiooooi4ufgPdC6OYm3TwUVcNIVKR+kgTXPehUZt01TfQZJ33+/nvk2TF4ReUS5n2HcvRUTKA0GagD4AsaoArlJdpyRYPWbmPYACEGUQcBwQakRYsuanTrBcdoVBOT2NmdOdDt0SQEb6UCHe+BrRcshjgUOq8TguzXw6z0jZbNyuNu9ZTw+DNbSalUnMxRbfY1t8Z0N/WSNM0ESr2W4rD2FBczASlywlLyCS0DU4i18itHTnRvAtxdvkcQSgZXFWRXEd8pS/h7Smw7DLWUdqtvP2AAr2w76mwhmSJc8QrO3CDiJea0Z84zIrGSL4X4osiL8h25i8APJWpP93obq03NdVDuXt/CtQGgmtG+YZEaxJ/1chwnnKdTaCMOH9vxwMimF1G+uo8DTQoq7C+GzvzgKuLzAQLdcpKgXHQT94FU+YQV36oYFipNzGJig8kHVfseZ7faJGYxsTezWVJDlkrTEajdaN5K4c0cSP8wV8eoEZjT4J3gAAAABJRU5ErkJggg==";
var newFile = new Parse.File("testing.png", imageS);
newFile.save({
success: function () {
console.log("Image Upload Succces");
},
error: function (file, error) {
console.log("Image Upload Error" + error.message);
}
})
但它显示无法使用该数据创建Parse.File。
答案 0 :(得分:1)
您可以创建一个Image对象并将base64作为其src:
var image = new Image();
image.src = 'data:image/png;base64,iVBORw...';
document.body.appendChild(image);
答案 1 :(得分:0)
首先查看Parse.File
的文档看起来好像会接受一个base64
属性设置为base64字符串的对象。 mime类型“image / png”是第三个参数,但可以从提供的文件名中推断出来。
数据网址中的base64字符串是"data:image/png;base64,"
前导后的所有内容。
根据此分析,您在Parse.File
调用中提供了错误的数据 - 它不会拍摄图像对象。