Editor Upload // Example of integration with Amazon S3 Bucket

Editor Upload // Example of integration with Amazon S3 Bucket

fabioberettafabioberetta Posts: 74Questions: 23Answers: 4

Good morning all,

I am using Editor Upload function to upload users photos and documents. I would like to use amazon S3 bucket as a repository for those documents.

I was wondering if this is possible and if an example of integration exists somewhere.

I did not find any evident google link.

ty
f

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Answer ✓

    Sorry, this is not something I have an example of. However, you could presumably use the S3 API (or ssh) to upload the file from your server-side script like you might with any other file.

    Allan

  • fabioberettafabioberetta Posts: 74Questions: 23Answers: 4
    edited June 2016

    Thanks Allan,

    I did try but despite it looked pretty simple I hit some issues with the namespace. It seems I cannot call the API functions from within the Upload constructor.

    I to not think it is a problem with your library .It is due to my limited knowledge of PHP namespaces.

    I will sitck with my filesystem or the moment. If I make it work I will try to post the example.

    ty
    f

  • ewmantheiewmanthei Posts: 14Questions: 1Answers: 2

    I wrote a solution to this problem. If anyone is interested, I can post what I did.

  • fabioberettafabioberetta Posts: 74Questions: 23Answers: 4
    edited July 2016

    I am interested!

    Please post it. i did some tests but rather unsuccessful, it would be great to have a working example to start with.

    ty
    f

  • ewmantheiewmanthei Posts: 14Questions: 1Answers: 2
    edited July 2016

    This is an example based upon one of my implementations using joins. I'm uploading images to s3 that I embed in a website, which is why the ACL is public-read. You may require other options. I recommend you vet every line of this code prior to implementing it yourself. It is simply an example. Use at your own risk.

    Also, I'm using aws php sdk v3.

    Editor::inst($db, 'table_name')
        ->fields(
            Field::inst('table_name.file_location')
                ->setFormatter('Format::ifEmpty', null)
                ->upload(
                    Upload::inst(function($file,$id){
                        require_once '/path/to/aws/cred/and/s3client/init';
                        try {
                            $result = $S3Client->putObject(array(
                                'Bucket' => 'BucketName',
                                'Key' => $file['name'],
                                'SourceFile' => $file['tmp_name'],
                                'ACL' => 'public-read',
                                'ContentType' => $file['type']
                            ));
                            return $result['ObjectURL'];
                        } catch (S3Exception $e) {
                            error_log(print_r($e, true));
                            return 'some error stuff';
                        }
                    })
                    ->db( 'table_name', 'table_name.id', array(
                        'table_name.file_location' => Upload::DB_FILE_NAME
                    ))
                    ->allowedExtensions( array( 'png', 'jpg', 'whateveryouwant'), "please upload images with the right extensions!")
                )
            ,
            Field::inst(........
    
This discussion has been closed.