Fernando P. G.
Fernando P. G.

Reputation: 191

Gaufrette upload image and store in AmazonS3

I'm using the bundle https://github.com/KnpLabs/Gaufrette and this is my configuration:

knp_gaufrette: 
    adapters:
        someadapter:
            amazon_s3:
                amazon_s3_id: service.amazon.s3
                bucket_name: %amazon.s3.bucket_name%
                create: true
    filesystems:
        somefilesystem:
            adapter: someadapter

I have a form in which I upload a file. My problem is that the file is upload in the /tmp/file directory and then I tried to move this file to amazon:

$filesystem->get('somefilesystem')->rename($tmpPath , $destinyPath);

an exception is throw:

The file "/tmp/phpR4YbZN" was not found.

It makes sense because the file is not already in amazon and I'm working on that filesystem. But I would like to know how I could to upload a file to AmazonS3 from my local filesystem.

Thanks!!!

Upvotes: 2

Views: 3576

Answers (1)

l3l0
l3l0

Reputation: 3393

Do you want to do such thing ? :

$filesystemMap
   ->get('somefilesystem')
   ->write($destinyPath, file_get_contents($tmpPath))
;`

just notice that write method have third "overwrite" argument (by default false).

You can register stream wrapper and work like with normal php file API/functions. Please see https://github.com/KnpLabs/KnpGaufretteBundle#stream-wrapper for more info.

Upvotes: 4

Related Questions