文件上传Podio API时出错

时间:2018-07-20 13:00:14

标签: podio

有人可以帮我在Podio中上传文件吗?我是Podio库的新手,所以我正在尝试但遇到很多错误。

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

我的代码如下:

ClassB.js

2 个答案:

答案 0 :(得分:0)

如错误消息所示:expects parameter 1 to be a valid path, resource given in /home/gphxyz/public_html/decode/podio-php/models/PodioFile.php on line 54

因此,请提供有效的本地文件路径,而不是$filepath = 'http://geeksperhour.xyz/decode/podio-php/credit.jpg';

答案 1 :(得分:0)

您可能会发现一段时间以来不建议使用用于文件上传的lib / podio.php。

在Github上查看公开票证:The usage of the @filename API for file uploading is deprecated - File upload #74

更改189行中的API将使您可以再次阅读文档。

来自

 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';
    } 

   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';
  }

在PHP 7.2 Ubuntu 16.04环境中为我工作。

还要确保文件的路径指向本地服务器的路径。

另外,如果您使用作曲家,您可能会发现指向主rather than the latest release很有用:

composer require podio/podio-php:dev-master