Facebook JavaScript SDK – Photo upload with FormData

Uploading a photo to Facebook is quite easy if the photo is on a server already. This tutorials explains how to upload a photo to Facebook directly from the device with FormData, without the need to upload in on a server first.

Old school URL upload

If you do not know how to use the JS SDK in general, i got you there: Facebook API – Login with the JavaScript SDK

You can also do this of user profiles with the publish_actions permission, of course.

Direct File Upload

So what if you just want to use a new photo from your disk, without uploading it to a server first? For that, you can use multiplart/form-data – but it´s a bit tricky because it seems that no one got it to work with the official JavaScript SDK. It works well with the fetch API though, you can also use axios or something else:

Use a file input field to choose the picture and load it with the FileReader object:


One thought on “Facebook JavaScript SDK – Photo upload with FormData

Leave a Reply

Your email address will not be published. Required fields are marked *