pinarkive/pinarkive-sdk-php
Composer 安装命令:
composer require pinarkive/pinarkive-sdk-php
包简介
PHP SDK for PinArkive API v3 – minimal client (upload, pin, remove, users/me, uploads, tokens, status, allocations). See https://docs.pinarkive.com
关键字:
README 文档
README
Minimal PHP client for the PinArkive API v3. Upload files, pin by CID, manage tokens, and check status. See docs.pinarkive.com.
Version: 3.1.2
Installation
composer require pinarkive/pinarkive-sdk-php
Quick Start
<?php use Pinarkive\PinarkiveClient; use Pinarkive\PinarkiveException; // Auth: token, apiKey, baseUrl (default: https://api.pinarkive.com/api/v3) $client = new PinarkiveClient(null, 'your-api-key-here'); // Upload a file $response = $client->uploadFile('document.pdf'); $data = json_decode($response->getBody(), true); echo $data['cid']; // Or login first $login = $client->login('user@example.com', 'password'); $data = json_decode($login->getBody(), true); $client = new PinarkiveClient($data['token'], null); // List uploads $response = $client->listUploads(1, 20); $data = json_decode($response->getBody(), true); print_r($data['uploads']);
Directory DAG (uploadDirectoryDAG)
The API expects multipart field files (repeated); each part’s filename is the path inside the DAG. The response root CID is cid.
$response = $client->uploadDirectoryDAG(['1.png', '2.png'], 'mydag', 'cl0-global'); $data = json_decode($response->getBody(), true); echo $data['cid']; // gateway …/ipfs/<cid>/1.png
Authentication
- Constructor:
new PinarkiveClient($token = null, $apiKey = null, $baseUrl = '...', $sendRequestSourceWeb = false) - API Key is sent as
X-API-Keyheader; token asAuthorization: Bearer <token>. - $sendRequestSourceWeb: when
true, sendsX-Request-Source: webon every Bearer-authenticated request (not when using API Key). Use from web apps so the backend classifies requests as WEB in logs instead of JWT.
API Methods (minimal set)
| Method | Description |
|---|---|
health() |
GET /health |
getPlans() |
GET /plans/ |
getPeers() |
GET /peers/ |
login($email, $password) |
POST /auth/login |
verify2FALogin($temporaryToken, $code) |
POST /auth/2fa/verify-login |
uploadFile($filePath, $clusterId = null, $timelock = null) |
POST /files/ |
uploadDirectory($dirPath, $clusterId = null, $timelock = null) |
POST /files/directory |
uploadDirectoryDAG($files, $dirName = null, $clusterId = null, $timelock = null) |
POST /files/directory-dag |
pinCid($cid, $originalName = null, $customName = null, $clusterId = null, $timelock = null) |
POST /files/pin/:cid |
removeFile($cid) |
DELETE /files/remove/:cid |
getMe() |
GET /users/me |
listUploads($page = 1, $limit = 20) |
GET /users/me/uploads |
generateToken($name, $label = null, $expiresInDays = null, $scopes = null, $totpCode = null) |
POST /tokens/generate |
listTokens() |
GET /tokens/list |
revokeToken($name, $totpCode = null) |
DELETE /tokens/revoke/:name |
getStatus($cid, $clusterId = null) |
GET /status/:cid |
getAllocations($cid, $clusterId = null) |
GET /allocations/:cid |
Optional $clusterId and $timelock (ISO 8601, premium) follow the API docs.
Error handling
On HTTP 4xx/5xx the client throws PinarkiveException with:
getStatusCode()— HTTP statusgetApiError()— API fielderrorgetApiMessage()— API fieldmessagegetApiCode()— API fieldcode(e.g.email_not_verified,missing_scope)getRequired()— for 403missing_scope: the required scopegetRetryAfter()— for 429: seconds until retry (from body orRetry-Afterheader)getBody()— full response array
try { $client->uploadFile('file.pdf'); } catch (PinarkiveException $e) { echo $e->getStatusCode() . ' ' . $e->getApiMessage() . ' ' . $e->getApiCode(); }
Changelog
3.1.2
- Docs: Links updated to https://docs.pinarkive.com.
3.1.0
- Request source: Constructor 4th param
$sendRequestSourceWeb = truesendsX-Request-Source: webon Bearer requests. - Scopes & 2FA:
generateToken(..., $scopes, $totpCode);revokeToken($name, $totpCode).verify2FALogin($temporaryToken, $code)for login with 2FA. - Errors:
getRequired()(403 missing_scope),getRetryAfter()(429).
3.1.1
- Fix:
uploadDirectoryDAGnow sends multipart with repeated field namefiles, with each part’s filename equal to the relative path in the DAG (backend multerupload.array('files')). The previousfiles[i][path]/files[i][content]format is not accepted by the backend.
See also CHANGELOG.md.
3.0.0
- API v3: Base URL is now
https://api.pinarkive.com/api/v3(was/api/v2). v1/v2 are deprecated (410). - Errors: On 4xx/5xx the client throws
PinarkiveExceptionwithgetStatusCode(),getApiError(),getApiMessage(),getApiCode(),getBody()(no raw Guzzle response on failure). - Minimal surface: Only endpoints documented at docs.pinarkive.com: health, plans, peers, login, files (upload, directory, directory-dag, pin, remove), users/me, uploads, tokens (generate with
name/label/expiresInDays), status, allocations. Optional$clusterIdand$timelock(ISO 8601) on upload/pin. - Removed:
renameFile; token optionspermissions,ipAllowlist. Use APIlabelandexpiresInDaysonly. - Constructor:
PinarkiveClient($token = null, $apiKey = null, $baseUrl = '...')— third argument is base URL (v2 had only apiKey and baseUrl). - Pin:
pinCidnow accepts$originalName,$customName(replacing the old single$filename).
Upgrading from 2.x
- Change base URL to
/api/v3or use the new default. - Add the third constructor argument if you use a custom base URL:
new PinarkiveClient(null, $apiKey, 'https://api.pinarkive.com/api/v3'). - Catch
PinarkiveExceptionand usegetStatusCode(),getApiMessage(),getApiCode()instead of Guzzle’sRequestException. - Use
pinCid($cid, $originalName, $customName, $clusterId, $timelock)instead ofpinCid($cid, $filename). - Use
generateToken($name, $label, $expiresInDays); droppermissionsandipAllowlistfrom options. - Require
pinarkive/pinarkive-sdk-php: ^3.0for v3.
Links
pinarkive/pinarkive-sdk-php 适用场景与选型建议
pinarkive/pinarkive-sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「php」 「api」 「sdk」 「laravel」 「v3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pinarkive/pinarkive-sdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pinarkive/pinarkive-sdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pinarkive/pinarkive-sdk-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
A PSR-7 compatible library for making CRUD API endpoints
Bundle Symfony DaplosBundle
Alfabank REST API integration
Biblioteca PHP pura para pagamentos SISP/Vinti4 de Cabo Verde.
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-13