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:
| Property | Description |
|---|---|
url | Media URL without the generated download token |
downloadUrl | Media URL containing the generated download token |
contentType | Detected MIME type |
downloadTokens | Generated Firebase Storage download token |
size | Object size in bytes |
updated | Storage update timestamp when available |
timeCreated | Storage creation timestamp when available |
bucket | Bucket name |
etag | Object ETag when available |
generation | Object generation when available |
nameAndPath | Sanitized 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.
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.