Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Accept metadata in options #7

Closed
MikeyVelt opened this issue Jan 25, 2017 · 6 comments
Closed

Accept metadata in options #7

MikeyVelt opened this issue Jan 25, 2017 · 6 comments

Comments

@MikeyVelt
Copy link

Hello there,
The getOptionsFromConfig method should accept the metadata key as a possible value.

I require this for the following properties:

  • "contentType": string
  • "contentLanguage": string
  • "cacheControl": string

The official google cloud documentation shows that the StorageObject allows the metadata property.
https://googlecloudplatform.github.io/google-cloud-php/#/docs/v0.20.1/storage/storageobject?method=update

And the JSON API docs shows what properties the StorageObject can contain.
https://cloud.google.com/storage/docs/json_api/v1/objects#resource

@Codestudios
Copy link

How can i Put file with custom Control-Cache metadata?
Storage::disk('public')->put($path, 'public');

@matthewgoslett
Copy link
Contributor

You can pass it in the 'metadata' key when 'putting' the object.

@Rafeethu
Copy link

i tried several ways, but couldn't set the cache value. i tried

Storage::putFileAs('path', $image_file, $type.'.png', ['visibility' => 'public', 'cacheControl' => 'no-cache, max-age=0']);

Storage::putFileAs('path', $image_file, $type.'.png', ['visibility' => 'public', 'metadata' => ['cacheControl:no-cache, max-age=0'] ]);

Storage::putFileAs('path', $image_file, $type.'.png', ['visibility' => 'public', 'metadata' => ['cacheControl ' => 'no-cache, max-age=0'] ]);

any clue?

@ultrono
Copy link

ultrono commented Feb 27, 2020

Same here, I cannot pass metadata, I need to pass cache control and expires headers.

Previously when using s3,w here I wanted all uploads to have set meta data, within the filesystems.php config I had the following, that worked fine:

's3' => [
            'driver' => 's3',
            'key' => env('AWS_KEY'),
            'secret' => env('AWS_SECRET'),
            'region' => env('AWS_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
            'options' => [
                'CacheControl' => 'max_age=31536000',
                'Expires' => gmdate("D, d M Y H:i:s T", strtotime("+3 years")),
                'visibility' => 'public',
            ],
        ],

I'm unsure if https://github.com/Superbalist/laravel-google-cloud-storage/blob/master/src/GoogleCloudStorageServiceProvider.php#L29 is affecting this.

@JoyJulianGomes
Copy link

@Rafeethu
Storage::disk('gcs')->getDriver()->put('sitemap/test.txt', 'test', ['visibility' => 'public', 'metadata' => ['cacheControl' => 'no-store']])
this one worked for me.

@Darkyn
Copy link

Darkyn commented May 9, 2023

Just in case anyone comes across this in the future (I'm using Digital Ocean in my case here), it turns out that to pass in custom metadata, you have to use the keyword "Metadata" with an uppercase "M", otherwise it's ignored. I don't know if that's a Laravel limitation, or an API requirement, but if you just use "metadata" with a lowercase "m", the metadata will be ignored.

Therefore the options array would look like this:
['Metadata' => ['the_name' => 'the_value']]

The uploaded file in my case then has a new custom metadata element that looks like this:
x-amz-meta-the_name : the_value

I assume the "amz" here is because it's s3 compatible, but no clue lol

Hope this helps someone.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants