Hello forum!
I’m using Livewire v1.3.3.
I’m developing with Mix which uses BrowserSync and I have the setting mix.browserSync('http://project.loc');
in my webpack.mix.js file. So the URL from which I’m trying to upload is localhost:3000.
When uploading an image with the Livewire’s WithFileUploads trait enabled, I’m getting CORS error when I select a file:
Reason: header ‘x-csrf-token’ is not allowed according to header ‘Access-Control-Allow-Headers’ from CORS preflight response
The request is going to http://project.loc/livewire/upload-file?expires… instead of localhost:3000/livewire/upload-file?expires… maybe this is also a problem?
My .env
file has APP_URL=http://project.loc
. Changing this to http://localhost:3000
doesn’t make any difference.
I’ve shortened the class bellow so as to make it more readable.
The function startUpload()
here is copied from the trait and the temporary link is dumped. At this point I get the correct url when I try to upload a file. But if I remove the dd()
the upload posts to the wrong url.
class FileUploadComponent extends Component
{
use WithFileUploads;
public $photo;
public function updatedPhoto()
{
$this->validate([
'photo' => 'image|max:24',
]);
}
public function startUpload($name, $fileInfo, $isMultiple)
{
$link = URL::temporarySignedRoute(
'livewire.upload-file', now()->addMinutes(5)
);
dd($link);
$this->emitSelf('upload:generatedSignedUrl', $name, $link);
}
}
I guess when emitting the event upload:generatedSignedUrl
to UploadManager.js the link somehow gets updated.
Maybe I’m missing something in Livewire config? Any help would be appreciated, thank you!