0
votes

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:

How to connect Laravel 5 app with object-storage bucket?

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?

1
Some things I noticed here, the problem may not have anything to do with laravel, since all you are doing is calling apis.. secondly, this IBM service looks to be backed by AWS so y using both IBM and Laravel, you are limiting who is going to think they have knowledge. Better off maybe just saying cannot access AWS file after upload, IBM resells this kinda stuff all the time.Dan Chase
IBM COS is accessible via S3 API, but the storage service is definitely not by Amazon... :)data_henrik
I'm going to look into Laravel, but are you 100% sure that the bucket was created in the eu-gb region?Nick Lange

1 Answers

0
votes

I did so.

$response = $filesystem->put($new_name, file_get_contents($file), ['ACL' => 'public-read']  );

try this

Storage::disk('object-storage')->put($full_name,$file, ['ACL' => 'public-read']);