I am trying to post a file using jQuery post
, and get TypeError: Illegal invocation
function fbUpload(token){
var dataURL = canvas.toDataURL('image/jpeg', 1.0)
var blob = dataURItoBlob(dataURL)
$.post( "https://graph.facebook.com/me/photos", {
'access_token': token,
'source': blob
}, function( data ) {
console.log(data);
});
}
Could it be because of the 'blob'?
This is working fine:
function fbUpload(token){
var dataURL = canvas.toDataURL('image/jpeg', 1.0)
var blob = dataURItoBlob(dataURL)
var formData = new FormData()
formData.append('access_token', token)
formData.append('source', blob)
var xhr = new XMLHttpRequest();
xhr.open( 'POST', 'https://graph.facebook.com/me/photos', true )
xhr.onload = xhr.onerror = function() {
console.log( xhr.responseText )
};
xhr.send( formData )
}
You need to use $.ajax
and provide the FormData
object to the data
parameter. $.post
only takes data as a string or as a plain object. Try this:
function fbUpload(token){
var dataURL = canvas.toDataURL('image/jpeg', 1.0)
var blob = dataURItoBlob(dataURL)
var formData = new FormData()
formData.append('access_token', token)
formData.append('source', blob)
$.ajax({
url: "https://graph.facebook.com/me/photos",
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(data) {
console.log(data);
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With