Skip to main content
Version: 4.0

File uploads

FirestoreFileUpload stores Laravel and Livewire uploads in Google Cloud Storage and returns Firebase-compatible download URLs and object metadata.

Configure storage​

GOOGLE_CLOUD_STORAGE_BUCKET=your-project.appspot.com
FIREBASE_CREDENTIALS=/absolute/path/to/service-account.json

The service account must have permission to create objects in the bucket.

Restrict size and MIME types in config/firebase.php:

'upload' => [
'max_size' => 10 * 1024 * 1024,
'allowed_mime_types' => [
'image/jpeg',
'image/png',
'application/pdf',
],
],

An empty allowed_mime_types array allows every detected MIME type. Application validation is still required.

Laravel request upload​

Validate the request, then pass the input name and optional storage path:

use Illuminate\Http\Request;
use Roddy\FirestoreEloquent\FileUpload\FirestoreFileUpload;

public function store(Request $request)
{
$request->validate([
'document' => ['required', 'file', 'mimes:jpg,jpeg,png,pdf', 'max:10240'],
]);

$upload = FirestoreFileUpload::upload('document', 'ride-documents');

return response()->json($upload);
}

Livewire upload​

Pass Livewire's temporary uploaded-file object:

use Livewire\Component;
use Livewire\WithFileUploads;
use Roddy\FirestoreEloquent\FileUpload\FirestoreFileUpload;

class UploadDocument extends Component
{
use WithFileUploads;

public $document;

public function save()
{
$this->validate([
'document' => ['required', 'file', 'mimes:jpg,jpeg,png,pdf', 'max:10240'],
]);

$upload = FirestoreFileUpload::uploadLivewire(
$this->document,
'ride-documents',
);

// Persist $upload->downloadUrl or $upload->nameAndPath.
}
}

Return value​

Both methods return an object with:

PropertyDescription
urlMedia URL without the generated download token
downloadUrlMedia URL containing the generated download token
contentTypeDetected MIME type
downloadTokensGenerated Firebase Storage download token
sizeObject size in bytes
updatedStorage update timestamp when available
timeCreatedStorage creation timestamp when available
bucketBucket name
etagObject ETag when available
generationObject generation when available
nameAndPathSanitized path and generated object name

The package sanitizes path segments, creates a UUID-based filename, enforces the configured size and MIME allow-list, and streams the local upload to the bucket.

Download-token access

Anyone with downloadUrl can access the object through its token. Treat the URL as sensitive when files are private, and apply appropriate bucket rules and application authorization.