Reputation: 48439
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",
));
Upvotes: 1
Views: 1568
Reputation: 197
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);
Upvotes: 1
Reputation:
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.
Upvotes: 0