I did not get this to work with the official JS SDK (with FB.api), but this is how it works easily with a file input:const fileReader = new FileReader();const file = document.getElementById('imageInput').files[0];fileReader.onloadend = async () => { const photoData = new Blob([fileReader.result], {type: 'image/jpg'}); const formData = new FormData(); formData.append('access_token', pageAccessToken); formData.append('source', photoData); formData.append('message', 'some status message'); let response = await fetch(`https://graph.facebook.com/${pageId}/photos`, { body: formData, method: 'post' }); response = await response.json(); console.log(response);};fileReader.readAsArrayBuffer(file);无需额外的插件,FileReader和fetch API是本机Javascript功能.No additional plugin neccessary, FileReader and fetch API are native Javascript features.如果输入是画布对象的Base64字符串,则可以使用以下命令:使用JavaScript中的base64字符串创建Blob If the input is a Base64 String of a canvas object, you can use this: Creating a Blob from a base64 string in JavaScript更多信息: http://www .devils-heaven.com/facebook-javascript-sdk-photo-upload-with-formdata/ 这篇关于使用Facebook的JavaScript API发布多部分/表单数据编码的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-23 19:26