0

I need to use Amazon S3 with CI3, so my plan is making a library called AmazonS3 where i will have basic methods like up() delete() tokenize() just for example.
I have installed S3 using composer inside the application/s3 directory.
**Code of my Library: **

<?php 
defined('BASEPATH') OR exit('u no here!');

use Aws\S3\S3Client;

class AmazonS3 {

private $s3;
private $bucket;

function __construct()
{
    $this->bucket = 'images.secret.com';

    require 'application/s3/vendor/autoload.php';

    $this->s3 = S3Client::factory([
        'key' => 'super-key---',
        'secret' => 'thats-a-long-string'
    ]);
}

public function up()
{
    $this->s3->putObject([
        'Bucket' => $this->bucket,
        'Key' => 'images/test.jpg',
        'Body' => fopen('application/img/test.jpg', 'rb'),
        'ACL' => 'public-read'
    ]);
}

}

This up() method is just a testing purpose, the way i called this from another controller is looks like:

    $this->load->library('amazons3');
    $this->amazons3->up();

WHich gives me few ton's of error. What i am missing?

rakibtg
  • 5,521
  • 11
  • 50
  • 73

1 Answers1

0

Okay, i found the solution and it is not a codeigniter issue, i was missing the region part of the factory settings!

rakibtg
  • 5,521
  • 11
  • 50
  • 73