PHPackages                             rakk7/directo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. rakk7/directo

ActiveLibrary[File &amp; Storage](/categories/file-storage)

rakk7/directo
=============

A library to generate signatures for direct upload to Amazon S3

v0.3(6y ago)07MITPHPPHP &gt;=5.5.0

Since Oct 30Pushed 6y agoCompare

[ Source](https://github.com/rakk7/Directo)[ Packagist](https://packagist.org/packages/rakk7/directo)[ RSS](/packages/rakk7-directo/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (2)Versions (5)Used By (0)

Directo
=======

[](#directo)

A library to generate AWS Signature V4 and supplement form inputs, for direct upload to Amazon S3. Includes a bridge to Laravel as-well.

Install
-------

[](#install)

```
$ composer require kfirba/directo
```

Prerequisites - CORS &amp; Bucket Policy
----------------------------------------

[](#prerequisites---cors--bucket-policy)

In order for the upload to succeed and not get denied by Amazon S3 we will need to configure the CORS option and the bucket policy.

To update the CORS and the bucket policy, log in to your AWS account and go to S3. Now select your bucket and click **Properties** on the top-right corner. Click on **Permissions**.

To update the CORS configuration, click the **Edit CORS Configuration** button. I recommend the following CORS configuration:

```

        *
        GET
        POST
        PUT
        3000
        *

```

To update the bucket policy, click the **Edit bucket policy** button. I recommend the following bucket policy:

```
{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Effect": "Allow",
			"Principal": "*",
			"Action": [
				"s3:PutObject",
				"s3:PutObjectAcl"
			],
			"Resource": "arn:aws:s3:::BUCKET_NAME/*"
		}
	]
}
```

Don't forget to change `BUCKET_NAME` to your bucket's name.

**Note:** If you don't plan to ever upload any file with any other ACL than `private`, you may want to omit the `"s3:PutObjectAcl"`.

Laravel Users
-------------

[](#laravel-users)

If you are a Laravel user, the package contains a bridge for you.

Update your **app.php** `providers` array and add:

```
Kfirba\Directo\Support\DirectoServiceProvider::class,
```

Also, update your `aliases` array and add:

```
'Directo' => Kfirba\Directo\Support\Facades\Directo::class,

```

If you need to change some of the default settings, you can either publish the `directo.php` config to make the changes global every time you try to generate a signature, or use the convenient setter **Directo** provides.

```
$ php artisan vendor:publish --tag=directo
```

You should now be able to find a `directo.php` file in your `config/` directory with all of the default options.

```
// You can also change the options on-the-fly
Directo::setOptions(['acl' => 'private'])->inputsAsArray();
```

The on-the-fly change is useful especially when you may have more than 1 form in your document and one of them may require different options than the other one. For example, a form to upload some private metrics data to S3, you will want to set the `acl` to `private` and a form to upload a profile picture which you will want to set the `acl` to atleast `public-read`.

The package reads your S3 configurations specified in `config/filesystems.php` under the `disks.s3` array. To change the configs, you can change the following keys in your `.env` file:

```
S3_KEY=myS3Key
S3_SECRET=myS3Secret
S3_REGION=eu-central-1
S3_BUCKET=bucket

```

Laravel then reads these environment variables and set the config in `filesystems.disks.s3` which **Directo** uses.

Usage
-----

[](#usage)

```
use Kfirba\Directo\Directo;

require_once __DIR__ . "/vendor/autoload.php";

$directo = new Directo('bucket', 'region', 'key', 'secret', $options = []);
```

Then, using the object we've just made, we can generate the form's url and all the needed hidden inputs.

```
