pubpackage / filestack-php
PHP的Filestack库
1.2.0
2021-10-27 08:15 UTC
Requires
- php: >=7.3
- guzzlehttp/guzzle: ~6.5 || ~7.3
Requires (Dev)
- ext-json: *
- mockery/mockery: dev-master
- php-coveralls/php-coveralls: ^2.2
- phpmd/phpmd: @stable
- phpunit/phpunit: ^9.0
README
Filestack PHP
这是Filestack官方的PHP SDK - API和内容管理系统,它使向任何Web或移动应用程序添加强大的文件上传和转换功能变得容易。要求
- PHP 7.3+
资源
安装
使用composer安装filestack
,可以运行
$ composer require --prefer-dist filestack/filestack-php
使用方法
Filestack库为您提供对三个有用的类的访问
FilestackClient
- 用于轻松上传文件(创建Filelink对象)Filelink
- 用于文件处理(下载、转换等)FileSecurity
- 用于将策略和签名值应用于您的API调用
上传文件
首先,您需要创建FilestackClient的实例
use Filestack\FilestackClient; $client = new FilestackClient('YOUR_API_KEY');
调用upload()函数
$filelink = $client->upload('/path/to/file');
存储
默认情况下使用Amazon S3存储您的文件。如果您想使用不同的存储,您可以在调用upload()和store调用时传递额外的参数'location'
$client = new FilestackClient('YOUR_API_KEY'); $extras = [ 'Location' => 'dropbox', 'Filename' => 'somefilename.jpg', ]; $filepath = '/path/to/file'; $filelink = $client->upload($filepath); # get metadata of file $metadata = $client->getMetaData($filelink->handle, $fields); # get content of a file $content = $client->getContent($filelink->handle); # download a file $destination = '/path/to/file'; $result = $client->download($filelink->handle, $destination); # overwrite a file $filelink2 = $client->overwrite('/path/to/file', $filelink->handle);
操作文件
可以通过两种方式创建Filelink对象
- 通过使用FilestackClient上传文件
- 通过使用文件句柄和api_key初始化Filelink
如上所示,第一种方法,第二种方法也非常简单,并将创建表示已上传文件的对象。
use Filestack\filelink; $filelink = new Filelink('some-file-handle', 'YOUR_API_KEY'); # transforming an image $transformed_filelink = $filelink ->circle() ->blur(['amount' => '20']) ->save(); # get metadata $metadata = $filelink->getMetaData(); # get content of a file $content = $filelink->getContent(); $filepath = '/path/to/file'; # download a file $filelink->download($filepath); # overwrite remote file with local file $filelink->overwrite($filepath); # delete remote file $filelink->delete();
标记文件和检测适合工作内容
use Filestack\FilestackClient; use Filestack\FilestackSecurity; $security = new FilestackSecurity('YOUR_SECURITY_SECRET'); $client = new FilestackClient('YOUR_API_KEY', $security); $file_handle = 'some-file-handle'; # get tags with client $result_json = $client->getTags($file_handle); # get tags with filelink $filelink = new Filelink($file_handle, 'YOUR_API_KEY', $security); $json_result = $filelink->getTags(); # get safe for work flag with client $result_json = $client->getSafeForWork($file_handle); # get safe for work flag with filelink $json_result = $filelink->getSafeForWork();
有关更多示例,请参阅本项目中的examples/文件夹。
智能摄取
智能摄取功能允许用户以不确定大小的块上传文件。这创建了一个更稳定的上传流程,确保正在上传的文件最终会成功完成,无论网络延迟或超时错误。
然而,对于大文件,上传过程可能比正常上传流程慢,因为错误会使用指数退避重试策略重试。
最后,必须为使用的apikey启用此功能。要启用此功能,请联系Filestack至support@filestack.com。
$client = new FilestackClient('YOUR_API_KEY');
$filelink = $client->upload('/path/to/file', ['intelligent' => true]);
版本控制
Filestack PHP SDK遵循语义版本控制。
代码标准
- PSR-2编码标准 (http://www.php-fig.org/psr/psr-2/)
- PSR-4自动加载标准 (http://www.php-fig.org/psr/psr-4/)
- phpDoc文档注释标准 (https://www.phpdoc.org/docs/latest/getting-started/your-first-set-of-documentation.html)
测试
- 要运行测试,从项目根目录运行
vendor/bin/phpunit
- 要生成覆盖率报告,运行以下命令(将在coverage/目录下生成html文件)
vendor/bin/phpunit --coverage-xml=coverage
- 要运行PHPMD进行CodeClimate检查
vendor/bin/phpmd filestack xml phpmd-rules.xml > logs/phpmd-report-filestack.xml
vendor/bin/phpmd tests xml phpmd-rules.xml > logs/phpmd-report-tests.xml
生成文档
要获取项目度量,请使用https://github.com/sebastianbergmann/phploc的phar文件
./phploc.phar --log-xml=phploc.xml .
要生成文档,请使用https://github.com/theseer/phpdox的phar文件
./phpdox.phar
问题
如果您有问题,请创建Github问题。
贡献
有关详细信息,请参阅CONTRIBUTING.md。
致谢
感谢所有贡献者。