File "S3SimpleUploadController.php"

Full Path: /var/www/drive/foundation/src/Files/S3/S3SimpleUploadController.php
File size: 1.08 KB
MIME-type: text/x-php
Charset: utf-8

<?php

namespace Common\Files\S3;

use Carbon\Carbon;
use Common\Core\BaseController;
use Common\Files\Actions\ValidateFileUpload;
use Common\Files\S3\InteractsWithS3Api;

class S3SimpleUploadController extends BaseController
{
    use InteractsWithS3Api;

    public function __construct()
    {
        $this->middleware('auth');
    }

    public function     presignPost()
    {
        $fileKey = $this->buildFileKey();

        $errors = app(ValidateFileUpload::class)->execute(request()->all());
        if ($errors) {
            abort(422, $errors->first());
        }

        $command = $this->getClient()->getCommand('PutObject', [
            'Bucket' => $this->getBucket(),
            'ContentType' => request()->input('mime'),
            'Key' => $fileKey,
            'ACL' => $this->getAcl(),
        ]);

        $uri = $this->getClient()
            ->createPresignedRequest($command, Carbon::now()->addHour())
            ->getUri();

        return $this->success([
            'url' => $uri,
            'key' => $fileKey,
            'acl' => $this->getAcl(),
        ]);
    }
}