Skip to content

Instantly share code, notes, and snippets.

@shanerbaner82
Created August 7, 2021 03:20
Show Gist options
  • Save shanerbaner82/2f1d8513ecb567cf5fba35d0a7583167 to your computer and use it in GitHub Desktop.
Save shanerbaner82/2f1d8513ecb567cf5fba35d0a7583167 to your computer and use it in GitHub Desktop.
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
class UploadToIpfs extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'uploadfiles';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$images = \Storage::allFiles('images');
$bar = $this->output->createProgressBar(count($images));
$bar->start();
foreach ($images as $image) {
$file = Storage::path($image);
$info = (pathinfo($file));
$filename = $info['basename'];
Http::withHeaders([
'pinata_api_key' => 'api-key',
'pinata_secret_api_key' => 'secret',
])
->attach('file', file_get_contents($file), $filename)
->post('https://api.pinata.cloud/pinning/pinFileToIPFS');
sleep(1);
$bar->advance();
}
$bar->finish();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment