Created
August 7, 2021 03:20
-
-
Save shanerbaner82/2f1d8513ecb567cf5fba35d0a7583167 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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