Need help with Google Drive integration in Laravel Filament
I’m working on a project where I need to store files directly to Google Drive instead of local storage. Here’s what I’m trying to achieve:
- Use Filament’s file upload component to send multiple documents to Google Drive
- Retrieve the uploaded files from Google Drive storage
- Show these files in an iframe on a different page
Is this kind of integration actually doable? I’ve been searching but haven’t found clear examples of how to make Filament’s file upload work with Google Drive API. Any guidance on the best approach would be really helpful.
Has anyone successfully implemented something similar? What challenges should I expect?
Yeah, totally doable but you’ll hit some setup headaches. Grab the laravel-google-drive package - don’t build this from scratch. The tricky part is Filament’s upload component wants local paths, so you’ll need to intercept uploads and push them to Google Drive instead. For iframe display, Google Drive’s embed URLs work great - just add ‘/preview’ to any sharing URL. Use service accounts for auth like everyone’s saying, but turn on domain-wide delegation if you’re running GSuite.
I built something almost identical for a document management system last year. It’s definitely doable but you’ll need custom work since Filament doesn’t support Google Drive natively. You’ll need to create a custom storage driver using Laravel’s filesystem config and the Google Drive API client. The trickiest part was OAuth authentication - use service account credentials instead of user OAuth for server-side stuff. For iframe display, generate shareable links from Google Drive since direct URLs need authentication. I ended up making a custom Filament component that handles uploads and iframe rendering. The upload component saves the Google Drive file ID to your database, then you use that ID to generate embed URLs for iframes. Big challenge is file permissions - decide if files should be public or if you want to proxy them through Laravel for access control.
You’ll need to set up Laravel’s filesystem with Google Drive as a custom disk. Configure the Google API client in your services config and create a service provider for Google Drive operations. The tricky part is getting Filament’s FileUpload component to work - you’ll have to override its default behavior so it saves files to Google Drive instead of local storage. For the iframe display, you can’t directly embed Google Drive files because of CORS issues. Instead, create a Laravel route that grabs the file content from Google Drive and streams it back with the right headers. Store the Google Drive file metadata in your database - file ID, sharing permissions, all that stuff. Just heads up - performance can be pretty slow since every file operation calls Google’s API. I’d recommend caching frequently accessed documents. Also, Google Drive has daily API limits that could bite you if you’re doing heavy file operations.