NozmaD
NozmaD
FFilament
Created by NozmaD on 1/9/2025 in #❓┊help
Cancell file upload
Hi. How can I cancel the file upload to FileUpload? The verification condition is as follows: if the name of the uploaded file is not found in the database, then cancel its download.
protected function getFormSchema(): array
{
$currentTenantId = Filament::getTenant()->id;
$UserMatchList = \App\Models\Goods\Case\UserMatchList::query()
->where('cabinet_id', $currentTenantId)
->get()
->map(function ($item) {
return $item->vendor_code;
})
->toArray();

$component = Components\FileUpload::make('attachments')
->hiddenLabel()
->directory("cases/{$currentTenantId}")
->acceptedFileTypes(['image/jpeg'])
->multiple()
->preserveFilenames()
->fetchFileInformation(false)
->moveFiles(true)
->panelLayout('grid')
->afterStateUpdated(function (Set $set, Components\FileUpload $component, $state, $livewire) use ($UserMatchList) {

/** @var \Livewire\Features\SupportFileUploads\TemporaryUploadedFile $file */
foreach ($state as $file) {
$path = $file->getRealPath();
$fileName = pathinfo($path, PATHINFO_FILENAME);

if (!in_array($fileName, $UserMatchList)) {
Notification::make()
->title('Filename Error')
->danger()
->send();
$file->delete();// Dont work
return;
}
}
});


return [
Components\Fieldset::make('cases')
->schema([$component])

];
}
protected function getFormSchema(): array
{
$currentTenantId = Filament::getTenant()->id;
$UserMatchList = \App\Models\Goods\Case\UserMatchList::query()
->where('cabinet_id', $currentTenantId)
->get()
->map(function ($item) {
return $item->vendor_code;
})
->toArray();

$component = Components\FileUpload::make('attachments')
->hiddenLabel()
->directory("cases/{$currentTenantId}")
->acceptedFileTypes(['image/jpeg'])
->multiple()
->preserveFilenames()
->fetchFileInformation(false)
->moveFiles(true)
->panelLayout('grid')
->afterStateUpdated(function (Set $set, Components\FileUpload $component, $state, $livewire) use ($UserMatchList) {

/** @var \Livewire\Features\SupportFileUploads\TemporaryUploadedFile $file */
foreach ($state as $file) {
$path = $file->getRealPath();
$fileName = pathinfo($path, PATHINFO_FILENAME);

if (!in_array($fileName, $UserMatchList)) {
Notification::make()
->title('Filename Error')
->danger()
->send();
$file->delete();// Dont work
return;
}
}
});


return [
Components\Fieldset::make('cases')
->schema([$component])

];
}
15 replies
FFilament
Created by NozmaD on 3/27/2024 in #❓┊help
How to create a table from a file
How to do something like this: There is a file that I am loading, it is supposed to be temporary, I am guessing that I need to use sushi. The scheme is as follows: I go to the resource, where the file upload form is immediately shown, I upload the xlsx file, after which it is processed and displays the information in the form of a table. There is no need to save it all, process it once, display information and that's it
4 replies