I am trying to setup my Laravel application to use the Object Storage service from IBM-Cloud. What I want is to upload a file and get a static public URL foreach file, but I am currently having some trouble to access the file after upload.
Installed package:
league/flysystem-aws-s3-v3
Created a new service provider for the bluemix storage suggested in this post:
Within my controller I use the following call to upload the file:
Storage::disk('object-storage')->put($full_name,$file);
Upload works fine, and I can see the file in the bucket. The problem appears when I am trying to access the file.
According to the IBM documentation I need to set the ACL to public-read to be able to access the file publicly. After some research I modified the Filesystem call:
Storage::extend('object-storage', function($app, $config) {
$client = S3Client::factory([
'credentials' => [
'key' => $config['key'],
'secret' => $config['secret'],
],
'region' => $config['region'],
'version' => $config['version'],
'endpoint' => $config['endpoint'],
]);
$adapter = new AwsS3Adapter($client, $config['bucket_name']);
return new Filesystem($adapter,['ACL' => 'public-read']);
});
I have also tried to set the visibility trough the Storage call in the controller:
Storage::disk('object-storage')->setVisibility($full_name,'public-read');
Then I tried to access the file to read the visibility by using the getVisibility:
Storage::disk('object-storage')->getVisibility($full_name);
This gives me an 404 error on getObjectAcl with message:
The specified key does not exist on https://bucket-name.s3.eu-gb.objectstorage.softlayer.net/sApQNtdUvJYg7YWsL8IbCe26U6EK8v.png?acl
If I try to copy the URL address and paste it in my browser I get Access Denied error.
The authentication credentials that is used within the calls is set as Manager.
Is there anyone who has a solution for this problem, or does it exist any guide to upload and read the files using Laravel?
eu-gb
region? – Nick Lange