grandwebdesign/digitalocean-spaces-laravel

This package will help uploading and removing assets to digitalocean spaces

1.2.2 2023-08-20 09:22 UTC

This package is auto-updated.

Last update: 2024-10-20 11:55:09 UTC


README

This package provides easy integration and management of DigitalOcean Spaces in Laravel applications.

Requirements

  • PHP >= 8.1
  • Laravel >= 10.0

Installation

To install the package via Composer:

composer require grandwebdesign/digitalocean-spaces-laravel

Configuration

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=

Usage

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