|
| 1 | +Uplink PHP client |
| 2 | +============= |
| 3 | + |
| 4 | +Client for decentralized object storage on [Tardigrade.io](https://tardigrade.io/) |
| 5 | + |
| 6 | +[▶ 40 second video](https://www.youtube.com/watch?v=QOjM5ERd8yo&feature=youtu.be) |
| 7 | + |
| 8 | +Requirements |
| 9 | +---------- |
| 10 | + |
| 11 | +- Tardigrade API key |
| 12 | +- PHP >= 7.4 |
| 13 | +- Linux x64 |
| 14 | + |
| 15 | +Installation |
| 16 | +--------- |
| 17 | + |
| 18 | +1. Enable the FFI in php.ini: |
| 19 | + |
| 20 | +``` |
| 21 | +extension=ffi |
| 22 | +``` |
| 23 | + |
| 24 | +2. (optional) To use it in web request also adjust this setting from "preload" to "true": |
| 25 | + |
| 26 | +``` |
| 27 | +ffi.enable=true |
| 28 | +``` |
| 29 | + |
| 30 | +3. Install using composer. Copy and run: |
| 31 | + |
| 32 | +``` |
| 33 | +composer config repositories.storj/uplink '{ |
| 34 | + "type": "package", |
| 35 | + "package": { |
| 36 | + "name": "storj/uplink", |
| 37 | + "version": "0.1.0", |
| 38 | + "license": "MIT/Expat", |
| 39 | + "dist": { |
| 40 | + "url": "https://build.dev.storj.io/job/uplink-php/job/PR-8/14/artifact/release.zip", |
| 41 | + "type": "zip" |
| 42 | + }, |
| 43 | + "autoload": { |
| 44 | + "psr-4": { |
| 45 | + "Storj\\Uplink\\": "src/" |
| 46 | + } |
| 47 | + }, |
| 48 | + "autoload-dev": { |
| 49 | + "psr-4": { |
| 50 | + "Storj\\Uplink\\Test\\": "test/" |
| 51 | + } |
| 52 | + }, |
| 53 | + "require": { |
| 54 | + "php": ">=7.4", |
| 55 | + "ext-ffi": "*", |
| 56 | + "psr/http-message": "^1.0" |
| 57 | + }, |
| 58 | + "require-dev": { |
| 59 | + "phpunit/phpunit": "^9.2" |
| 60 | + } |
| 61 | + } |
| 62 | +}' && |
| 63 | +composer require storj/uplink |
| 64 | +``` |
| 65 | + |
| 66 | +Usage |
| 67 | +---- |
| 68 | + |
| 69 | +For better response times of your web app, you should serialize your credentials to an access string. |
| 70 | + |
| 71 | +```php |
| 72 | +require 'vendor/autoload.php'; |
| 73 | +$access = \Storj\Uplink\Uplink::create()->requestAccessWithPassphrase( |
| 74 | + '12L9ZFwhzVpuEKMUNUqkaTLGzwY9G24tbiigLiXpmZWKwmcNDDs@europe-west-1.tardigrade.io:7777', |
| 75 | + 'mybase58apikey', |
| 76 | + 'mypassphrase' |
| 77 | +); |
| 78 | +$serialized = $access->serialize(); |
| 79 | +echo $serialized; |
| 80 | +``` |
| 81 | + |
| 82 | +If you have already used uplink-cli you can read this from `~/.local/share/storj/uplink/config.yaml` |
| 83 | +or share it using `$ uplink share` |
| 84 | + |
| 85 | +You can then use this in your web app: |
| 86 | + |
| 87 | +```php |
| 88 | +$access = \Storj\Uplink\Uplink::create()->parseAccess($serialized); |
| 89 | +``` |
| 90 | + |
| 91 | +Examples: |
| 92 | + |
| 93 | +- [raw/upload.php](examples/raw/upload.php) Upload files via a HTML form |
| 94 | +- [raw/download.php](examples/raw/download.php) Download files via the browser |
| 95 | +- [psr/FormUploadHandler.php](examples/psr/FormUploadHandler.php) Upload files via a HTML form in a PSR-7 framework |
| 96 | +- [psr/DownloadHandler.php](examples/psr/FormUploadHandler.php) Stream a PSR-7 HTTP response |
| 97 | + |
0 commit comments