【问题标题】:Error in file uploading Podio API文件上传 Podio API 时出错
【发布时间】:2018-12-28 19:12:10
【问题描述】:

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

警告:realpath() 期望参数 1 是有效路径,资源在 /home/gphxyz/public_html/decode/podio-php/models/PodioFile.php 第 54 行 警告:filesize() 期望参数 1 是有效路径,资源在第 54 行的 /home/gphxyz/public_html/decode/podio-php/models/PodioFile.php 中给出 致命错误:未捕获的 PodioBadRequestError:“'source' 参数必须以 multipart/form-data 的形式给出,类型为 'file'” 请求网址:http://api.podio.com/file/v2/ 堆栈跟踪:#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(资源 id #72, 'http://geeksper...') #3 {main} 在第 289 行的 /home/gphxyz/public_html/decode/podio-php/lib/Podio.php 中抛出

我的代码如下:

<?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);

【问题讨论】:

    标签: podio


    【解决方案1】:

    您可能会发现用于文件上传的 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 环境中为我工作。

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

    另外,如果您使用 composer,您可能会发现指向 master rather than the latest release 很有用:

    composer require podio/podio-php:dev-master

    【讨论】:

      【解决方案2】:

      正如错误消息所说: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';

      【讨论】:

      • 我改变了路径,脚本现在是 $filepath = 'public_html/decode/podio-php/credit.jpg';但仍然面临许多错误警告:filesize(): stat failed for /public_html/decode/podio-php/credit.jpg in /home/gphxyz/public_html/decode/podio-php/models/PodioFile.php 在第 54 行致命错误:未捕获的 PodioConnectionError:连接到 Podio API 失败:[26] 在 /home/gphxyz/public_html/decode/podio-php/lib/Podio.php:261 中创建表单发布数据失败:261 堆栈跟踪:#0 /home/gphxyz/public_html/ decode/podio-php/lib/ 请提出什么问题?任何帮助都会非常重要。
      • 请编辑您的问题,不要在 cmets 中粘贴代码和异常。它不可读:(另外:我很确定public_html/decode/podio-php/credit.jpg 不是有效的本地路径。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-09
      • 2020-08-19
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多