With store route in laravel i pass data (text) to MySQL and image to storage. However i cant store images on local storage (after new deploy) changes in file system resets so i need to do it with external storage. Whats the easiest way to store images (low size) and to have permission to fetch them (with js)?
You need to store them to something persistent, like Amazon S3.
You can use Laravel's Storage system for this. Once you've set up an S3 disk with the right AWS credentials, it's as simple as:
$path = $request->file('your-field')->store('your-folder', 's3')
or:
$path = Storage::disk('s3')->put('path/to/folder', new File('/path/to/temporary/file'));
I encountered the same problem recently and here is what I figured out for a solution:
Heroku does not have storage for images, which calls for using a service that stores images for free and use it.
OR
You can just move them to the public folder instead of the storage folder, and use this in your view code:
<img src="{{ secure_asset($whereEverYouStoredYourImage->theImageAttribute) }}" alt="example">
Related
I'm saving images from local disk to cloud (DO storage) disk by following codes in controller
$claim->addMediaFromDisk($front_image, 'public')->usingFileName("front-image")->toMediaCollection('claim-images', 'do_spaces');
$claim->addMediaFromDisk($right_image, 'public')->usingFileName("right-image")->toMediaCollection('claim-images', 'do_spaces');
$claim->addMediaFromDisk($left_image, 'public')->usingFileName("left-image")->toMediaCollection('claim-images', 'do_spaces');
this trick works but saving those images in 3 different directory in cloud storage. But I want all three images in same directory.
I see there is built in method for adding multiple media from request. But how can I do it form disk. I was expecting something like addMultipleMediaFromDisk(!). Is there any solution ?
Laravel version: 7.30
Spatie media library version: 7.20
//where the original file is saved on the local disk and the conversions on S3.
$media = $claim->addMedia($pathToImage)->storingConversionsOnDisk('s3')
->toMediaCollection('claim-images', 'local');
I have a Laravel 5 app which was previously storing images locally. I have now modified it so that images are stored on an S3 server, I previously retrieved the local images like this...
$image_contents = Storage::get('myimages/logos/' . $image->filename);
Now I have moved to S3 storage, how can I instead get the image from the S3 bucket?
It's the same but you have to put your AWS bucket path:
Storage::disk('s3')->get('AWS_BUCKET_PATH');
Laravel 5.6 custom storage link/mount to other location on Windows OS
https://laravel.com/docs/5.6/filesystem#configuration
php artisan storage:link will point the
http://localhost/storage to c:/project/storage/app/public
means visit http://localhost/storage/image.jpg = c:/project/storage/app/public/image.jpg
but how to custom the uri link to other location ? eg..
http://localhost/ramdisk/image.jpg link to z:/ramdisk/image.jpg
or
http://localhost/avatar/image.jpg link to z:/avatar/image.jpg
First of all: why would you like to do that? The images you upload should be in /storage/app/... or in /public/images/... Other disks may be unavailable if putting the app on a server.
To clarify, the php artisan storage:link only creates a symlink in /public/ folder pointing to the app/public. (I think in 5.6 it has absolute path so on server or after moving the application you have to delete and generate it again.)
So if you really want to access disk z on your PC from the app you should create a symlink in /public/ folder with the desired name. For example:
http://localhost/ramdisk/... would be a symlink named ramdisk in the public folder and would point to z:/ramdisk/. Then you would be able to access the folder contents as you wish.
Of course you can have multiple symlinks so you would create another one for the avatar folder too. Also make sure that disk z has a public access.
I was not able to test it, but I am sure that it would work, however I would not recommend it. If you want to use something in your app it should be within the app. (Except S3 drivers like amazon cloud storage.) I hope it helped.
I store images using this method:
'avatar' => $r->avatar->store('public/avatars')
and get them like
<img src="{{Storage::url($user->avatar)}}" style="border-radius:50%;height:30px;width:30px;" style alt="">
They get displayed on the local machine, but not in others. What could be the issue?
Check the value of user's avatar column, you might have some sort symlinks enabled on local machine, Instead you can also use public_path, as storage should not be exposed outside.
https://laravel.com/docs/5.6/helpers#method-public-path
Also check file visibility
https://laravel.com/docs/5.6/filesystem#storing-files
you have stored file inside public/avatars
be sure $user->avatar has public/avatars concatenated if not you might have to
{{Storage::url("public/avatars/".$user->avatar)}}
use this as source of your image
had to delete the public/storage folder on the other machine then run
php artisan storage:link
images started showing as normal
im fairly new to laravel and im currently working on a project that needs to store files in the server. What im doing is store it under public/docs the problem is the files under that directory is accessible all the time given that they know the url to the certain file. for example even if they are logged out if they know this url http://localhost/dummy/public/uploads/docs/2016-06-02-10-52-43-oth-content-inventory-and-planning-spreadsheet.pdf they would be able to access it what im thinking is to do something like this
in my routes i would do something like
Route::any('uploads/docs/' , 'go to some controller to check if user can acces');
is this possible? thanks in advance!
it's called public for a reason...
you should use storage instead (laravel 5) in storage you dont restrict access, actualy the opposite, you grant access to the file .
try this for laravel 4.2 (move the file after upload like this to a storage folder)
Input::file('file')->move(__DIR__.'/storage/',Input::file('file')->getClientOriginalName());
});
Anyway ,the conclusion is that you can't restrict access (you shouldn't even if there is a way) because it's meant to be public ! so you should use storage folder(or whatever its called in laravel 4)