项目作者: filestack

项目描述 :
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.
高级语言: PHP
项目地址: git://github.com/filestack/filestack-php.git
创建时间: 2017-04-25T14:31:15Z
项目社区:https://github.com/filestack/filestack-php

开源协议:Apache License 2.0

下载


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

  1. $ 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

  1. use Filestack\FilestackClient;
  2. $client = new FilestackClient('YOUR_API_KEY');

Call the upload() function

  1. $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

  1. $client = new FilestackClient('YOUR_API_KEY');
  2. $extras = [
  3. 'Location' => 'dropbox',
  4. 'Filename' => 'somefilename.jpg',
  5. ];
  6. $filepath = '/path/to/file';
  7. $filelink = $client->upload($filepath);
  8. # get metadata of file
  9. $metadata = $client->getMetaData($filelink->handle, $fields);
  10. # get content of a file
  11. $content = $client->getContent($filelink->handle);
  12. # download a file
  13. $destination = '/path/to/file';
  14. $result = $client->download($filelink->handle, $destination);
  15. # overwrite a file
  16. $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.

  1. use Filestack\filelink;
  2. $filelink = new Filelink('some-file-handle', 'YOUR_API_KEY');
  3. # transforming an image
  4. $transformed_filelink = $filelink
  5. ->circle()
  6. ->blur(['amount' => '20'])
  7. ->save();
  8. # get metadata
  9. $metadata = $filelink->getMetaData();
  10. # get content of a file
  11. $content = $filelink->getContent();
  12. $filepath = '/path/to/file';
  13. # download a file
  14. $filelink->download($filepath);
  15. # overwrite remote file with local file
  16. $filelink->overwrite($filepath);
  17. # delete remote file
  18. $filelink->delete();

Tagging files and detecting safe for work content

  1. use Filestack\FilestackClient;
  2. use Filestack\FilestackSecurity;
  3. $security = new FilestackSecurity('YOUR_SECURITY_SECRET');
  4. $client = new FilestackClient('YOUR_API_KEY', $security);
  5. $file_handle = 'some-file-handle';
  6. # get tags with client
  7. $result_json = $client->getTags($file_handle);
  8. # get tags with filelink
  9. $filelink = new Filelink($file_handle, 'YOUR_API_KEY', $security);
  10. $json_result = $filelink->getTags();
  11. # get safe for work flag with client
  12. $result_json = $client->getSafeForWork($file_handle);
  13. # get safe for work flag with filelink
  14. $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.

  1. $client = new FilestackClient('YOUR_API_KEY');
  2. $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

    1. vendor/bin/phpunit
  • To generate coverage report, run following command (will generage html files under
    directory coverage/)

    1. vendor/bin/phpunit --coverage-xml=coverage
  • To run PHPMD for CodeClimate checks

    1. vendor/bin/phpmd filestack xml phpmd-rules.xml > logs/phpmd-report-filestack.xml
    2. 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

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

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

  1. ./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.