上传跑道文件时出错 API
Error in file uploading Podio API
有人可以帮我在跑道上传文件吗?我是跑道图书馆的新手,所以我正在尝试,但遇到了很多错误。
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
我的代码如下:
<?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);
如错误消息所述: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';
您可能会发现用于文件上传的 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
有人可以帮我在跑道上传文件吗?我是跑道图书馆的新手,所以我正在尝试,但遇到了很多错误。
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
我的代码如下:
<?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);
如错误消息所述: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';
您可能会发现用于文件上传的 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