This package provides easy integration and management of DigitalOcean Spaces in Laravel applications.
- PHP >= 8.1
- Laravel >= 10.0
To install the package via Composer:
composer require grandwebdesign/digitalocean-spaces-laravel
Once you've installed the package, set the following environment variables in your .env file:
DO_ACCESS_KEY_ID=
DO_SECRET_ACCESS_KEY=
DO_DEFAULT_REGION=
DO_BUCKET=
DO_CDN_ENDPOINT=
DO_ENDPOINT=
DO_FOLDER=
Note on DO_FOLDER: This variable can remain empty if you want to upload files to the root directory. Otherwise, specify a folder name, such as "uploads"
, so all files will be uploaded to the /uploads/
path.
If you want to compress the image files as you upload you also need to specify your TinyPNG API key to your .env
file.
TINIFY_API_KEY=
To upload a file
use Grandwebdesign\DigitaloceanSpacesLaravel\DigitaloceanSpaces;
$digitaloceanSpace = new DigitaloceanSpaces(
file: $this->file('image'),
folder: '',
fileName: 'filename.png'
);
$fileName = $digitaloceanSpace->upload();
To remove a file
use Grandwebdesign\DigitaloceanSpacesLaravel\DigitaloceanSpaces;
$digitaloceanSpace = new DigitaloceanSpaces(
file: 'filename.png',
);
$fileName = $digitaloceanSpace->delete();