1

Can someone please help me in uploading file in Podio? I am new in Podio library so I am trying but getting lots of errors.

Warning: realpath() expects parameter 1 to be a valid path, resource given in /home/gphxyz/public_html/decode/podio-php/models/PodioFile.php on line 54

Warning: filesize() expects parameter 1 to be a valid path, resource given in /home/gphxyz/public_html/decode/podio-php/models/PodioFile.php on line 54

Fatal error: Uncaught PodioBadRequestError: "'source' parameter must given as multipart/form-data with type 'file'" 
Request URL: http://api.podio.com/file/v2/ 
Stack Trace: #0 /home/gphxyz/public_html/decode/podio-php/lib/Podio.php(352): Podio::request('POST', '/file/v2/', Array, Array) 
             #1 /home/gphxyz/public_html/decode/podio-php/models/PodioFile.php(54): Podio::post('/file/v2/', Array, Array) 
             #2 /home/gphxyz/public_html/decode/podio-php/index.php(22): PodioFile::upload(Resource id #72, 'http://geeksper...') 
             #3 {main} thrown in /home/gphxyz/public_html/decode/podio-php/lib/Podio.php on line 289

My code is below:

<?php
require_once 'PodioAPI.php';

//Initalize Podio connection
$client_id = ''; 
$client_secret = ""; 

Podio::setup($client_id, $client_secret);

//App ID's
$opname_app_id = '21209880';
$opname_app_token = "";  

Podio::authenticate_with_app($opname_app_id, $opname_app_token);
$opname_auth = Podio::$oauth;

$filepath = 'http://geeksperhour.xyz/decode/podio-php/credit.jpg';
$filename = 'credit.jpg';

$goFile = PodioFile::upload($filepath, $filename);
$fileID = $goFile->file_id;
print_r($fileID);
krlzlx
  • 5,752
  • 14
  • 47
  • 55
sonu
  • 23
  • 4

2 Answers2

0

As error message says: expects parameter 1 to be a valid path, resource given in /home/gphxyz/public_html/decode/podio-php/models/PodioFile.php on line 54

So, please provide valid local file path instead of $filepath = 'http://geeksperhour.xyz/decode/podio-php/credit.jpg';

Pavlo - Podio
  • 2,003
  • 2
  • 10
  • 19
  • 1
    I have changed path and script is now $filepath = 'public_html/decode/podio-php/credit.jpg'; But still facing many errors Warning: filesize(): stat failed for /public_html/decode/podio-php/credit.jpg in /home/gphxyz/public_html/decode/podio-php/models/PodioFile.php on line 54 Fatal error: Uncaught PodioConnectionError: Connection to Podio API failed: [26] failed creating formpost data in /home/gphxyz/public_html/decode/podio-php/lib/Podio.php:261 Stack trace: #0 /home/gphxyz/public_html/decode/podio-php/lib/ what can be the issue please suggest? Any help would be great appreciable. – sonu Jul 23 '18 at 07:48
  • Please edit your question and don't paste code and exception in comments. It's unreadable :( Also: I'm pretty much sure `public_html/decode/podio-php/credit.jpg` is not valid local path. – Pavlo - Podio Jul 25 '18 at 23:44
0

You might find that lib/podio.php for file uploads is deprecated since a while.

See the open Ticket on Github: The usage of the @filename API for file uploading is deprecated - File upload #74

Changing the API in line 189 will allow you to follow the documentation again.

from

 if (!empty($options['upload'])) {
      curl_setopt(self::$ch, CURLOPT_POST, TRUE);
      curl_setopt(self::$ch, CURLOPT_SAFE_UPLOAD, FALSE);
      curl_setopt(self::$ch, CURLOPT_POSTFIELDS, $attributes);
      self::$headers['Content-type'] = 'multipart/form-data';
    } 

to

   if (!empty($options['upload'])) {
      $cfile = curl_file_create(substr($attributes[ "source" ], 1));
      // Assign POST data
      $attributes[ "source" ] = $cfile;
      curl_setopt(self::$ch, CURLOPT_POST, TRUE);
      curl_setopt(self::$ch, CURLOPT_POSTFIELDS, $attributes);
      self::$headers['Content-type'] = 'multipart/form-data';
  }

Worked for me in a PHP 7.2 Ubuntu 16.04 environment.

Also make sure the path to your file is pointing to local a path of your server.

Additional if you use composer you might find it useful to point to the master rather than the latest release:

composer require podio/podio-php:dev-master

leopold
  • 1,971
  • 1
  • 19
  • 22