Hi team, I’m using cake php 5 and josegonzalez/cakephp-upload.
I was successful in using the local adaptor and upload files to the server.
I wanted to switch to aws S3 adaptor. I followed most of this: josediazgonzalez.com/2015/12/05/uploading-files-and-images/
but used the v7 docs here: github.com/FriendsOfCake/cakephp-upload/blob/7.x/docs/examples.rst
I keep getting this error: Laminas\Diactoros\UploadedFile could not be converted to string
I tried this setting in config/app.php ‘uploadedFilesAsObjects’ => false, → no joy.
to set up the flysystem I installed it via composer and on aws i set up my bukket using these IAM premissions: Aws S3 (v3) Adapter - Flysystem
here is some code from my FilesTable.php
use Aws\S3\S3Client;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
//.... other code
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('files');
$this->setDisplayField('original_name');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
// see config/.env.example and make a copy to .env.local and set your vars there
$client = new S3Client([
'credentials' => [
'key' => env('AWS_S3_ACCESS_KEY'),
'secret' => env('AWS_S3_ACCESS_SECRET'),
],
'region' => env('AWS_S3_REGION', 'eu-west-2'),
'version' => env('AWS_S3_VERSION', 'latest'),
]);
$adapter = new AwsS3V3Adapter(
$client,
env('AWS_S3_BUCKET_NAME', 'numa'), //bucket name
env('PROJECTID', 'testFiles') //optional/path/prefix here like a project/ website id
);
$this->addBehavior('Josegonzalez/Upload.Upload', [
'actual_name' => [
'path' => 'loader',
'filesystem' => [
'adapter' => $adapter,
],
],
]);
}
In my controller I can go around error by setting the filename it saves the record to the db with out error but the file does not make to my s3 bucket.
public function add()
{
$file = $this->Files->newEmptyEntity();
if ($this->request->is('post')) {
$file = $this->Files->patchEntity($file, $this->request->getData());
// if we uncomment the 3 lines below no error but no file in bucket either
// $image = $this->request->getData('actual_name');
// $fileName = $image->getClientFilename();
// $file->actual_name = $fileName;
if ($this->Files->save($file)) {
$this->Flash->success(__('The file has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The file could not be saved. Please, try again.'));
}
$this->set(compact('file'));
}
not doing anything extraordinary just uploading files. Any help appreciated, and thanks in advance.