filestack/filestack-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

filestack/filestack-php

Composer 安装命令:

composer require filestack/filestack-php

包简介

A Filestack library for PHP

README 文档

README

Filestack PHP

This is the official PHP SDK for Filestack - API and content management system that makes it easy to add powerful file uploading and transformation capabilities to any web or mobile application.

Requirements

  • PHP 8.3+

Resources

Installing

Install filestack with composer, either run

$ composer require --prefer-dist filestack/filestack-php

Usage

Filestack library gives you access to three useful classes:

  • FilestackClient - for easy file upload (creates Filelink objects)
  • Filelink - for file handling (downloading, converting etc.)
  • FileSecurity - for applying policy and signature values to your API calls

Uploading files

First, you need to create an instance of FilestackClient

use Filestack\FilestackClient;

$client = new FilestackClient('YOUR_API_KEY');

Call the upload() function

$filelink = $client->upload('/path/to/file');

Storage

Amazon S3 is used to store your files by default. If you wish to use a different one, you can pass in additional parameter 'location' when making upload() and store calls

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

Manipulating files

Filelink objects can be created in two ways:

  • by uploading a file using FilestackClient
  • by initializing Filelink with file handle and api_key

First method was shown above, the second method is also very easy and will create objects representing files that were already uploaded.

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

Tagging files and detecting safe for work content

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

For more examples, see the examples/ folder in this project.

Intelligent Ingestion

The Intelligent Ingestion feature allows user to upload a file in chunks of not precised size. This creates a more stable upload flow that ensures the file being uploaded will eventually complete successfully, regardless of network latency or timeout errors.

However, the upload process may be slower than the normal upload flow for large files, as there are errors are retried using the exponential backoff retry strategy.

Lastly, this feature has to be turned on for the apikey being used. To turn on this feature please contact Filestack at support@filestack.com.

$client = new FilestackClient('YOUR_API_KEY');
$filelink = $client->upload('/path/to/file', ['intelligent' => true]);

Versioning

Filestack PHP SDK follows the Semantic Versioning.

Code Standard

Testing

  • To run tests, from the project root director, run
vendor/bin/phpunit
  • To generate coverage report, run following command (will generage html files under directory coverage/)
vendor/bin/phpunit --coverage-xml=coverage
  • To run PHPMD for CodeClimate checks
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

Generating documentation

To get project metrics use phar file for https://github.com/sebastianbergmann/phploc

./phploc.phar --log-xml=phploc.xml .

To generate documentation use phar file from https://github.com/theseer/phpdox

./phpdox.phar

Issues

If you have problems, please create a Github Issue.

Contributing

Please see CONTRIBUTING.md for details.

Credits

Thank you to all the contributors.

filestack/filestack-php 适用场景与选型建议

filestack/filestack-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 590.12k 次下载、GitHub Stars 达 58, 最近一次更新时间为 2017 年 05 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 filestack/filestack-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 filestack/filestack-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 filestack/filestack-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 590.12k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 59
  • 点击次数: 6
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 58
  • Watchers: 13
  • Forks: 34
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2017-05-18