Reputation: 902
I have uploaded a publicly accessible file to my local disk. I can see it in my IDE at storage/app/public/mysubdir/myfile.js.
I have run the artisan command to create a symlink to the public directory. And I can also see the file at public/storage/mysubdir/myfile.js.
Yet when I go to http://my.app/storage/mysubdir/myfile.js I get the error "NotFoundHttpException in RouteCollection.php line 179".
Any ideas? Do I need to add some special route? Or update Nginx?
I have followed https://laravel.com/docs/5.4/requests#storing-uploaded-files and https://laravel.com/docs/5.4/filesystem#the-public-disk
Cheers
Upvotes: 0
Views: 5978
Reputation: 902
I found out the problem. I originally ran php artisan storage:link
on my local machine rather than in the virtual machine. I deleted the symlink and re-ran php artisan storage:link
inside Vagrant/Homestead and then it started working.
Upvotes: 2
Reputation: 213
Please check my code upload image to store in public folder work on both local and server side
public function uploadImage(Request $request){
$file = Input::file('image');
if(empty($file)){
return Response()->json(['error' => "Image is required" ], 406);
}
$extension = $file->getClientOriginalExtension();
$filename = rand(11111111111,999999999999).'.'.$extension;
$tmp_path = public_path('users/thumbnail/');
$letmovefiles = $file->move($tmp_path, $filename);
$full = $tmp_path.$filename;
$destinationPath = public_path('users/');
if ($_FILES['image']) {
$image = Image::make($full);
$image->resize(600, 600)->save();
$new_path = $destinationPath;
rename($destinationPath,$new_path);
}
$getlnik = url('users/thumbnail').'/'.$filename;
return Response()->json(['url' => $getlnik ], 200);
}
Upvotes: 0
Reputation: 1559
be sure to store file publicly like this:
$request->file('file')->store('images', 'public');
and restore it something like that:
asset('storage/file.ext');
to know more:
Upvotes: 0