At my Digital Ocean basic application, I used CRUD photo folder under public directory at laravel. But when I deploy the application from GitHub repo, it remove all photos and make same with my GitHub repo. Is there anyway to exclude the custom folders under public directory of laravel?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there @rockoo,
This happens as the DigitalOcean App platform is based on Kubernetes, meaning that each deployment is a separate immutable container.
So after each redeployment, all changes to the container will be lost.
To sort this out, you need to use an Object Storage, like the DigitalOcean Spaces.
To do so, you can follow the instructions from step 5 of this tutorial here:
Basically, what you need to do is:
s3
driver:composer require league/flysystem-aws-s3-v3
.env
file:DO_SPACES_KEY=EXAMPLE7UQOTHDTF3GK4
DO_SPACES_SECRET=exampleb8e1ec97b97bff326955375c5
DO_SPACES_ENDPOINT=https://ams3.digitaloceanspaces.com
DO_SPACES_REGION=ams3
DO_SPACES_BUCKET=sammy-travellist
config/filesystems.php
you need to define the details for your S3 bucket as follows:'spaces' => [
'driver' => 's3',
'key' => env('DO_SPACES_KEY'),
'secret' => env('DO_SPACES_SECRET'),
'endpoint' => env('DO_SPACES_ENDPOINT'),
'region' => env('DO_SPACES_REGION'),
'bucket' => env('DO_SPACES_BUCKET'),
],
Still, in the same file, locate the cloud entry and change it to set the new spaces disk as the default cloud filesystem disk:
'cloud' => env('FILESYSTEM_CLOUD', 'spaces'),
<?php
use Illuminate\Support\Facades\Storage;
public function uploadPhoto(Request $request)
{
$photo->image = $request->image->store('/', 'spaces');
Storage::setVisibility($photo->image, 'public');
$photo->save();
return redirect()->route('home');
}
<img src="{{ asset('storage') . '/' . $photo->image }}" />
Once you implement the S3 driver or the DigitalOcean Space, you will have persistent storage, so when your users upload images via your app, the images will not be uploaded to the container inside the DigitalOcean App itself, but the S3 bucket, so once the container gets redeployed your images will stay intact on the object storage.
Hope that this helps. Let me know how it goes. Best, Bobby
Click below to sign up and get $100 of credit to try our products over 60 days!