Skeldar
Skeldar

Reputation: 153

How to store images with heroku laravel app

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)?

Upvotes: 1

Views: 1898

Answers (2)

Aymen Storm
Aymen Storm

Reputation: 11

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">

Upvotes: 1

ceejayoz
ceejayoz

Reputation: 180023

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'));

Upvotes: 1

Related Questions