3

I did upload an object with Cache-Control as parameter and it does not take effect in object storage bucket but it does in AWS S3 bucket using the same code:

$s3Client->putObject([
            'ACL' => 'public-read',
            'Bucket' => config('filesystems.disks.object-storage.bucket_name'),
            'CacheControl' => 'public, max-age=86400',
            'Key' => $path,
            'SourceFile' => $path,
        ]);

I don't really understand why the same code does not have same effect in both cloud buckets since both use S3 API.

The uploaded file has control-cache header in AWS S3 and the same file in IBM OO doesn't get the same result.

how can I set correctly control-cache header in object-storage file ?

2 Answers2

0

The IBM object storage currently does not have all the options as AWS S3, the valid API operations are listed here https://ibm-public-cos.github.io/crs-docs/api-reference

As you can see there is not support for control cache

  • thanks, I appreciate your ref, my last doubt is about the existence of some mechanism to set expiration header to my files in object storage and thus gain better performance, do you know how to do that ? – user8322093 Oct 13 '17 at 23:19
  • 1
    That only can be done for swift object storage, you need to set the header "X-Delete-At" and the time you want. see https://community.runabove.com/kb/en/object-storage/how-to-schedule-deletion-of-objects.html – Nelson Raul Cabero Mendoza Oct 14 '17 at 12:07
  • X-Delete-At deletes the file from object storage. What they mean by "Expires" and "Cache-Control" is to set HTTP headers, maybe via setHttpExpiresDate() and setCacheControl() so clients can cache the response until the given time or for a given period, so they don't keep hitting your bucket, using up requests and transfer. It seems this *may* be supported in the CLI (see: --cache-control), but unlike Oracle Cloud it isn't exposed on the web-based console; nor in Aspera Connect: https://cloud.ibm.com/docs/cloud-object-storage-cli-plugin?topic=cloud-object-storage-cli-ic-cos-cli#ic-upload-object – GreenReaper Jan 22 '20 at 00:46
0

It can be done now - at least, certainly through the IBM Cloud Object Storage CLI:

ibmcloud cos put-object --bucket bucket-name-here --cache-control "public, max-age=31536000" --body dir/file.jpg --key prefix/file.jpg

Assuming you have the rights to do this, it will result in a with the appropriate Cache-Control header. There are optional parameters for e.g. Content-Type as well, although it seemed to detect the correct one for a JPG. To replace metadata on existing files you may have to copy from the bucket to the same bucket, as is done here.

Prior to this I created a service account with HMAC and entered the credentials with ibmcloud cos config hmac. You may also need ibmcloud cos config region to set your default region first.

As for the API itself, setCacheControl() [and setHttpExpiresDate()] seem like what you need. For the REST API you may need Cache-Control to be part of the PUT - it has been listed as a "common header" since June 2018. I'm not sure this is how you achieve this goal via REST, but it seems likely - this is how you set Content-Type.

In the web console I wasn't able to see an equivalent to the way Oracle offers to set Cache-Control headers when selecting files to upload, as it starts uploading immediately upon drag-and-drop using Aspera Connect. (This is unfortunate, as it's a relatively user-friendly way to upload a moderate number of files with paths.)

GreenReaper
  • 1,121
  • 1
  • 15
  • 23