Facebook Graph API – Upload Photos – “Requires upload file”

Quick post here since I see a lot of questions about this out there.

If you’re trying to upload photos via Facebook’s Graph API and you’re getting an OAuthException with a message of “(#324) Requires upload file”, I can help you out.

Something seems to have changed with facebook.php recently – if you’re going to upload files, you have to explicitly set fileUpload to be true in the API. In my setup code, I just add a line as demonstrated below:

// Create our Application instance.
$facebook = new Facebook(array(
'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
'cookie' => true,
'fileUpload' => true,
));

Alternatively, if you’ve already set up your $facebook object, you can call:
$facebook->setFileUploadSupport(true);

Happy coding!

7 thoughts on “Facebook Graph API – Upload Photos – “Requires upload file””

  1. Hi,

    I am actually using pure Rest APIs to upload files from my Java Code.

    From what I can understand, I need to set fileUpload parameter to true. In terms of PHP sdk this is fine but I am not clear on what needs to be done in my case where I am using REST API directly.

    (Changing SDK at this point is not a feasible option for me at this time)

    Any help would be appreciated, Thanks

  2. Hi Vishal,

    It seems that the ‘fileUpload’ parameter is a PHP-only value. That is, it is unique to the SDK and not intrinsic to the SDK. However, the relevant lines from the PHP SDK read as follows:

    if ($this->useFileUploadSupport()) {
    $opts[CURLOPT_POSTFIELDS] = $params;
    } else {
    $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, ‘&’);

    In other words, if the SDK’s file upload support is enabled, set cURL’s ‘POSTFIELDS’ option to be equal to the $params array that was passed in. Otherwise, build a query using the same data and some other values (the else clause). If you need a bit more background, try downloading the PHP SDK here and examining it for more guidance: https://github.com/facebook/php-sdk/ . Best of luck! 🙂

Comments are closed.