3

I am trying to create event with picture, but when i upload picture to facebook it throws me an error (#324) Missing or invalid image file

this is the function to upload picture.

public function uploadFacebookEventPicture($fullPath, $eventId) {
    $mainImage = '@' . $fullPath;   
    $imgData = array(
        'picture' => $mainImage
    );
    try {
        $data = $this->facebook->api('/'.$eventId, 'post', $imgData);
        return $data;
    } catch (FacebookApiException $e) {
        error_log('Failed to attach picture to event. Exception: ' . $e->getMessage());
    }       
    return null;
} 

the par of code i use after form post

if ($file[$name]['error'] == 0) {
                                    $fileName = $file[$name]['name'];
                                    $fileInfo = pathinfo($fileName);
                                    $newFileName = md5($fileName . microtime()) . '.' . $fileInfo['extension'];
                                    $fullPath = $this->config->applications->uploadPath . $newFileName;
                                    $form->$name->addFilter('Rename', $fullPath);

                                    if ($form->$name->receive()) {
                                        $resize = new SimpleImage();
                                        $resize->load($fullPath);
                                        $resize->resizeToWidth($this->config->applications->resize->width);
                                        $resize->save($fullPath);
                                        // Gathering data for saving files information
                                        $fileInfo = array(
                                            'name' => $newFileName,
                                            'type' => FileTypes::IMAGE,
                                            'description' => 'Application: Uploaded from Events form in back-end',
                                        );

                                        $fileId = $dbFiles->save($fileInfo);

                                        $eventFileData = array(
                                            'event_id' => $eventId,
                                            'file_id' => $fileId,
                                            'main_image' => ($name == 'mainImage') ? 1 : 0
                                        );                                  
                                        $dbEventFiles->save($eventFileData);
                                        if ($name === 'mainImage') {
                                            $success = **$this->uploadFacebookEventPicture($fullPath, $eventData['fb_event_id']**);
                                        }
                                    }
                                }

facebook object is created with upload file true

 $facebook = new Facebook(array(
                'appId' => $config->facebook->appId,
                'secret' => $config->facebook->secret,
                'fileUpload' => true
            ));
divide by zero
  • 2,340
  • 5
  • 23
  • 34
  • Have you checked inside of `uploadFacebookEventPicture` that the path points to a readable image file? – CBroe Aug 28 '12 at 07:49
  • `$fullPath = $this->config->applications->uploadPath . $newFileName;` and the uploadPath is `applications.uploadPath = APPLICATION_PATH "/../public/uploads/"` `$mainImage = @/srv/www/vhosts/servername.co.uk/prjfolder/public/uploads/daddc1e54d5c64a2d68bb0fce73f67ea.jpg` – divide by zero Aug 28 '12 at 07:56
  • And this file is _readable_ by your script, and it is a valid image resource (no errors when you view it in your browser or download it and open it with an image viewer)? – CBroe Aug 28 '12 at 07:59
  • yep, image is uploaded, stored and i can view it in the browser, front end of application, but fb doesn't want to take it. – divide by zero Aug 28 '12 at 08:04
  • 2
    According to https://developers.facebook.com/docs/reference/api/event/#picture the parameter has to be named `source` (you’re using `picture` right now) and you have to post it against `/EVENT_ID/picture` – give that a try, please. – CBroe Aug 28 '12 at 08:27
  • 1
    `public function uploadFacebookEventPicture($fullPath, $eventId) { $imgData = array( 'picture' => '@' . realpath($fullPath) ); try { $data = $this->facebook->api('/'.$eventId . '/picture', 'post', $imgData); return $data; } catch (FacebookApiException $e) { error_log('Failed to attach picture to event. Exception: ' . $e->getMessage()); die($e->getMessage()); } return null; }` haven't solved the problem, but now script doesn't catch error, but still picture - doesn't appear, file_exists and is readable are true, checked that. – divide by zero Aug 28 '12 at 08:37
  • `$imgData = array( 'source' => '@' . realpath($fullPath)` – CBroe Aug 28 '12 at 08:48
  • 1
    doesn't help :( same behavior as with the code above – divide by zero Aug 28 '12 at 08:57
  • 2
    It seems that the cause of this issue is [facebook bug](https://developers.facebook.com/bugs/254007748035978) . – Darvex Aug 28 '12 at 08:58
  • I have tried both ways. 1) Upload the photo when creating the event. 2) Upload the photo AFTER creating the event. Both do not work. So, is this confirmed to be a bug? See my related post here: http://stackoverflow.com/q/12170518/66767 – wenbert Aug 30 '12 at 03:30

1 Answers1

1

According to Facebook bug tracker, this bug has been fixed: Bug tracker post

Status changed to Fixed

Code above works fine for uploading facebook event picture.

divide by zero
  • 2,340
  • 5
  • 23
  • 34