Question

It's possible to upload base64 encoded images directly without saving it using Facebook PHP SDK 3.1.1?

$facebook->setFileUploadSupport(true);
$facebook->api('/me/photos', 'POST', array(
    'source' => '@/mycoolpic.png', // No need to use FS, base64 encoded image
    'message' => "I'm cool",
));
Was it helpful?

Solution

No, not that I have been aware of, or found out searching. Make sure you use realpath() around the image name, to give the absolute path to the image.

OTHER TIPS

You can do as follow in PHP :

function base64_to_jpeg( $base64_string, $output_file ) {
  $ifp = fopen( $output_file, "wb" ); 
  fwrite( $ifp, base64_decode( $base64_string) ); 
  fclose( $ifp ); 
  return( $output_file ); 
}
$facebook->setFileUploadSupport(true);
$image = base64_to_jpeg( $your_base64_string, 'tmp.jpg' );
$args = array('message' => 'Some message');
$args['image'] = '@' . realpath( $image );
$data = $facebook->api('/your_user_id/photos', 'post', $args);
unlink($image);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top