The official PHP package for Fileboy. Upload files and video, build image transform URLs and read video data from Laravel or plain PHP.
Install
fileboy/fileboy1composer require fileboy/fileboy
1 2 3 4 5 6 7 8use Fileboy\Client; $fileboy = new Client(publicKey: getenv('FILEBOY_PUBLIC_KEY')); $file = $fileboy->uploadFile('report.pdf'); echo $file->id; // store this $fileboy->buildImageUrl($file->id, transforms: [['type' => 'resize', 'width' => 300]]);
Pass a path or an open file. The method returns the stored file's details. Save its id.
1 2 3 4 5 6$file = $fileboy->uploadFile( './exports/report.pdf', metadata: ['customerId' => 'cus_123', 'kind' => 'monthly-report'], ); echo $file->id; // save this
Fileboy fetches the file itself, so it never passes through your server.
1 2 3 4 5$photo = $fileboy->uploadFileFromUrl( 'https://example.com/photo.jpg', name: 'photo.jpg', expect: 'image/jpeg', );
URLs are built locally, with no request.
1 2 3 4 5 6// the details of one file: name, mime, size, hash, metadata $data = $fileboy->fetchFileData($file->id); // a URL for a file or an image $link = $fileboy->buildFileUrl($file->id, download: true); $thumb = $fileboy->buildImageUrl($photo->id, transforms: [['type' => 'resize', 'width' => 300]]);
Transforms run in the order you list them. The image service supports resize, format, quality, background and invert.
1 2 3 4 5$url = $fileboy->buildImageUrl($photoId, transforms: [ ['type' => 'resize', 'width' => 800], ['type' => 'format', 'format' => 'webp'], ['type' => 'quality', 'value' => 80], ]);
Videos are encoded in the background. Upload, then poll the video's data until it is ready.
1 2 3 4 5 6 7 8$video = $fileboy->uploadVideo('./clips/launch.mp4', name: 'Launch day'); // encoding runs in the background: poll until it is ready $data = $fileboy->fetchVideoData($video->id); $data['extractionStatus']; $fileboy->buildVideoManifestUrl($video->id, type: 'hls'); $fileboy->buildVideoPosterUrl($video->id);
1 2 3 4 5 6 7 8 9 10 11 12// app/Providers/AppServiceProvider.php $this->app->singleton(\Fileboy\Client::class, fn () => new \Fileboy\Client( publicKey: config('services.fileboy.public_key'), privateKey: config('services.fileboy.private_key'), )); // in a controller public function store(Request $request, \Fileboy\Client $fileboy) { $file = $fileboy->uploadFile($request->file('avatar')->getRealPath(), name: $request->file('avatar')->getClientOriginalName()); $request->user()->update(['avatar_id' => $file->id]); }
Check that a webhook really came from Fileboy. Pass the raw request body, exactly as received. The webhooks reference lists every event.
1 2 3 4 5 6 7 8 9 10 11 12use Fileboy\Webhook; $event = Webhook::verify( $request->getContent(), $request->headers->all(), config('services.fileboy.webhook_secret'), ); if ($event['type'] === 'video.ready') { echo $event['resource']['urls']['hls']; } // throws Fileboy\Exception\WebhookVerificationException when the signature or timestamp is wrong
The package README lists every method, the error classes and the transform options. Every endpoint is also in the API reference and the OpenAPI spec.