Looking to hire Laravel developers? Try LaraJobs
This package is not available.

ipfs-laravel maintained by fliq

Description
:package_description
Author
Last update
2023/03/31 02:09 (dev-master)
License
Downloads
15

Comments
comments powered by Disqus

IpfsLaravel

Latest Version on Packagist Total Downloads Build Status StyleCI

Interact with IPFS in Laravel.

Installation

Via Composer

composer require fliq/ipfs-laravel

Usage

Basic usage

$cid = Ipfs::add('Hello, IPFS')->first()['Hash'];

Ipfs::get($cid); // Hello, IPFS

Configuration

To publish your config run:

php artisan vendor:publish --tag=ipfs.config

Adding Files

You can flexibly add new files to IPFS using the add() method. You can add files from a string, a resource or an array, arrays will be json encoded. Use array keys to specify files names.

The second argument is an array of options more information on the IPFS documentation. The wrap-with-directoryoption will create an extra CID for the directory.

$resource = fopen('path/to/file.mp3');

$results = Ipfs::add([
    'hello.txt' => 'Hello, IPFS!', 
    'file.mp3' => $resource,
    'meta.json' => [
        'name' => 'Hello',
        'properties' => [...],
    ],
], ['wrap-with-directory' => true]);

$cid = $results->last()['Hash'];

Ipfs::get("{$cid}/hello.txt"); // Hello, IPFS!

Retrieving files

You can retrieve files using the cat(), get(), and json() methods.

  • cat()
  • get()
    • returns a string
  • json()
    • returns a json decoded array
$stream = Ipfs::cat($cid);

$str = Ipfs::get($cid);

$array = Ipfs::json($cid);

Asynchronous requests

Use the async() method to make asynchronous requests.

Async requests return Promises

Ipfs::async()->add($file)->then(function(array $results) {
    $results[0]; // do something
});

// or do multiple requests.
$ipfs = Ipfs::async();

$promises = [
    $ipfs->get($cid1),
    $ipfs->get($cid2),
];

$results = GuzzleHttp\Promise\Utils::unwrap($promises);

Testing

$ composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email author@email.com instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.