angularfacebook-graph-apiimage-uploading

Facebook image upload from local storage


I'm using Facebook graph API to post an Image to a page.

 UploadImage() {

let params = {
  url: "https://www.facebook.com/images/fb_icon_325x325.png",
  published: true,
  access_token: this.accessToken
};

this.fb.api('/543337362691456/photos', 'post', params).then().catch(this.handleError); }

This code works perfectly. But I want to select a file from computer and upload that image to facebook. In order to do that, How I'm suppose to set the url of a local file to

url:" "

if I just select the path of a file it gives an error

Error


Solution

  • The url parameter is for online/public photos only, the picture needs to be on a server already. Take a look at the API reference, you can also upload them as multipart/form-data: https://developers.facebook.com/docs/graph-api/reference/page/photos/#Creating

    Example: http://www.devils-heaven.com/facebook-javascript-sdk-photo-upload-with-formdata/