Search code examples
phpfacebookfacebook-graph-apifacebook-php-sdk

Can't Read Files : Your photos couldn't be uploaded. Photos should be less than 4 MB and saved as JPG, PNG, GIF, TIFF, HEIF or WebP files


While uploading this image to the page using graph API on Facebook I am receiving the error

  "error_user_title": "Can't Read Files",
  "error_user_msg": "Your photos couldn't be uploaded. Photos should be less than 4 MB and saved as JPG, PNG, GIF, TIFF, HEIF or WebP files.", 

The provided image is JPEG and also does not exceed the 4MB limitation. But if I use other JPEG images which is also less than 4MB then the API successfully uploads the image.

To test I even used the curl method provided in the documentation, (add access token)

curl -i -X POST \
 -d "url=https://admin.quickinfo.dk/qs/images/610401d546777.jpeg" \
 -d "published=false" \
 -d "<access-token" \
 "https://graph.facebook.com/me/photos" 

Using this code I can successfully reproduce the error and also test for other images which get uploaded successfully and I get the image ID returned from Facebook

Both of the images are accessible and are just a few Kb in size. Can anyone help me figure out why the first image cannot upload on Facebook?

Also if I directly create the post using the first image in the facebook's page dashboard it gets successfully created.


Solution

  • For anyone facing the same issue or issue related to an image in Facebook's graph API, I fixed it by removing the image's EXIF data using Imagick before the upload.

    I opened a bug report they said they found the bug but the fix would only be applied after a few months, which was never applied. They fixed the example image but didn't mention how to fix it by ourselves and I figured the only thing that we could do was remove or manipulate the EXIF data. In my case, the issue was happening when the image was taken from the mobile's Camera mostly from iPhone (forgot which ones) and Motorola.