Ok? Do you have some code to show?
And why use media library? I assume you are uploading the file for simple storage?
laravel v8
spatie media library : v9
php : 7.4
livewire : v2.1
I want to upload .cdr (coreldraw) using Laravel 8 form. when i upload the file, i get a zip file in the target folder
Ok? Do you have some code to show?
And why use media library? I assume you are uploading the file for simple storage?
if (isset($item['psd']) && $newFileDemo && !empty($item['psd']) && !(isset($item['psdOld']) && !empty($item['psdOld']))) {
$newFileDemo->addMedia($item['psd']->getRealPath())
->usingName($item['psd']->getClientOriginalName())
->toMediaCollection('psd');
}
//add media ai file
if (isset($item['ai']) && $newFileDemo && !empty($item['ai']) && !(isset($item['aiOld']) && !empty($item['aiOld']))) {
$newFileDemo->addMedia($item['ai']->getRealPath())
->usingName($item['ai']->getClientOriginalName())
->toMediaCollection('ai');
}
//add media pdf file
if (isset($item['pdf']) && $newFileDemo && !empty($item['pdf']) && !(isset($item['pdfOld']) && !empty($item['pdfOld']))) {
$newFileDemo->addMedia($item['pdf']->getRealPath())
->usingName($item['pdf']->getClientOriginalName())
->toMediaCollection('pdf');
}
//add media cdr file
if (isset($item['cdr']) && $newFileDemo && !empty($item['cdr']) && !(isset($item['cdrOld']) && !empty($item['cdrOld']))) {
$newFileDemo->addMedia($item['cdr']->getRealPath())
->usingName($item['cdr']->getClientOriginalName())
->toMediaCollection('cdr');
}
in Database https://user-images.githubusercontent.com/48515888/151664902-0ffdf35e-4ef7-4756-a5d7-c538e8c81c9e.png
Use media library because each product can have more than 100 files for easy file management The project is an e-commerce sale of publications So each product who will have a lot of examples are files of different sizes
@samehdev so why would it be a problem that it is zipped? It will just save you space on disk. And you cannot preview the file in the browser anyways
Is it because it doesn't work somehow or?
@Sinnbeck It is true that it does not work when downloading the file
@samehdev great then we have something to work with. What error are you getting?
Can you show the code for downloading it?
use Spatie\MediaLibrary\MediaCollections\Models\Media;
public function downloadFile(Media $media)
{
return response()->download($media->getPath(), $media->name);
}
Result: The zip file is downloaded and does not work even after changing the format
@samehdev changing the format? Do you mean just changing the filename? Did you try unzipping? Right click -> unzip
@Sinnbeck I also tried to unzip it, it extracts a lot of files and it doesn't work
@samehdev alot of files? Doesn't work? Can you give a bit more to go on?
@Sinnbeck Thank you for trying to help the problem is spatie medialibrary They change the file format of this type during upload, so when downloading it before downloading, we must also convert the file back to its original format in order for it to work, In other words, I convert the zip file to cdr before downloading it to the client
Please or to participate in this conversation.