F
Filament11mo ago
toeknee

S3 File Uploads

Guys, what am I missing? My S3 storage driver works fine in laravel, but when using FileUpload as per:
FileUpload::make('cv')
->label('CV')
->enableDownload()
->disk('s3')
->directory($dir)
->required()
->disablePreview()
->columnSpan(6),
FileUpload::make('cv')
->label('CV')
->enableDownload()
->disk('s3')
->directory($dir)
->required()
->disablePreview()
->columnSpan(6),
Nothing is uploaded to S3 and instead stays in the Livewire Tmp Dir. Why...
Solution:
make sure youre using getState() and not manually accessing the data from Livewire
Jump to solution
10 Replies
Dennis Koch
Dennis Koch11mo ago
Also after saving? Did you try removing directory()?
toeknee
toeknee11mo ago
After Saving we get a data array of:
"documents": {
"cv": {
"c24fde3e-708c-49bc-b261-ad7de8545225": {
"disk": "local"
}
},
}
"documents": {
"cv": {
"c24fde3e-708c-49bc-b261-ad7de8545225": {
"disk": "local"
}
},
}
Tried without directory and no different
Dennis Koch
Dennis Koch11mo ago
That's weird. Why is the disk even in there?
toeknee
toeknee11mo ago
I suspect it's becasue I'm not casting to array on the model. But I can't as it's a form build and one level deep i.e. ["data"]["documents"]["cv"] Starting to think I need to write my own save function for file uploads. which isn't a huge deal, but thought that was why we use Filepond to handle all that and just return the path for where it has been uploaded too? I am on a custom livewire component, so looks like I'll just look to handle the saving myself I suppose This works
if(array_key_exists('documents', $this->data)) {
foreach ($this->data['documents'] as $key => $document) {
// Clear the files array to convert to array of filenames
unset($this->data['documents'][$key]['file']);

// Loop through as we are an array
foreach ($document as $doc) {

// Set the store as
$doc->storeAs('system/' . \Str::slug($instance->team->name) . '/files/' . $instance_id,
$doc->getClientOriginalName(), 's3');
$file = $doc->store();
// set the file name into the files array
$this->data['documents'][$key]['file'][] = $file;
}
}
}
if(array_key_exists('documents', $this->data)) {
foreach ($this->data['documents'] as $key => $document) {
// Clear the files array to convert to array of filenames
unset($this->data['documents'][$key]['file']);

// Loop through as we are an array
foreach ($document as $doc) {

// Set the store as
$doc->storeAs('system/' . \Str::slug($instance->team->name) . '/files/' . $instance_id,
$doc->getClientOriginalName(), 's3');
$file = $doc->store();
// set the file name into the files array
$this->data['documents'][$key]['file'][] = $file;
}
}
}
But seems far to hacky @Dan Harrin sorry for the tag.. but running out of ideas and docs are slim on this one :/... Is the fileupload in a custom livewire component requiring us to manually save? Or implement an additional trait? Or do we need to run a custom function which is monitored to handle the file uploads?
Dan Harrin
Dan Harrin11mo ago
nope it should not require you to manually save
Solution
Dan Harrin
Dan Harrin11mo ago
make sure youre using getState() and not manually accessing the data from Livewire
Dan Harrin
Dan Harrin11mo ago
getState() is the thing that validates and stores files and saves relationships
toeknee
toeknee11mo ago
This is likely why! Thanks Dan, will double check it. I think I maybe using raw data from when I was storing for a resume function later
Dan Harrin
Dan Harrin11mo ago
please follow the "adding a form to a livewire component" docs ;)
toeknee
toeknee11mo ago
Bahaha tbf I added this ages ago, it’s just a slip of duplicating a function. Sorry Dan 🙈 Yep just remoted in and checked... I was validating it but then just returning $this->data :/ ffs. $this->getState does render the correct links etc Thanks a Bunch Dan, only wasted 3/4 of a day on it haha
Want results from more Discord servers?
Add your server
More Posts
syntax error, unexpected identifier "Stat", expecting "function" or "const"I am trying to make a widget on my materials resource page that shows the total number of materials How do I get the values of the latest item in a repeater?I'm using listeners on my repeater to create and delete items. I'm doing this because there is a rouXss attacks protectIn filament when i try adding script alert to text input it show me alert in page. it is dangerous. Testing for Infolist actions (hintAction)I have a `Filament\Infolists\Components\TextEntry` with a `hintAction`. Are there any action test meIs Filament 3.x suitable for customer-facing public apps?Hello! I've been shily following the progress for Filament in the recent past, and it's awesome! I Select::createOptionForm not always workHello, I'm using a Select with `createOptionForm` in RegisterTenant and EditTenant. It's working prTrying to debug : Company::setTranslation(): Argument #2 ($locale) must be of type string, null...Hi ! Has anyone here come across this error before? I'm a bit lost 😦 ```php class Company extends Form Builder and file uploadsHow are we handling nested state path form builder uploads? For example we have statePath('files') tfilament::user-avatar component not found after upgraden to v3I just upgraded to v3, but when i log in i get the error: Unable to locate a class or view for compoopen new tab from BulkactionIs it possible to open a route in a new tab from a bulkaction ? I would like to create an action tha