amazon s3 - How to set Content-Disposition with AWS PHP SDK v2 and CopyObject? -


i'm using aws php sdk v2.x copy objects between s3 buckets using following code:

<?php try {     self::$aws->copyobject(array(         'bucket'     => $target_bucket,         'key'        => $target_key,         'copysource' => $source_bucket . '/' . $source_key,         'content-disposition' => 'attachment',         //'content-disposition' => 'attachment; filename="' . basename($target_key) . '"'         //'contentdisposition' => 'attachment'         //'contentdisposition' => 'attachment; filename="' . basename($target_key) . '"'     )); } catch (aws\s3\exception\s3exception $e) {     echo 'error'; } 

the file copied s3 bucket without errors, i'm unable set the content-disposition in order force browser download file rather stream it. i've tried few options (commented out above) nothing seem work.

i've attempted pass value in metadata array though documentation says otherwise aws console lists content-disposition under metadata section.

if manually change content-disposition in aws console browser downloads file expected.

so, how can pass value s3 object correctly? can pass @ using copyobject() method?

the copyobject operation tricky, imo. think missing piece of puzzle metadatadirective parameter. try following:

$s3client->copyobject(array(     'bucket'     => $target_bucket,     'key'        => $target_key,     'copysource' => $source_bucket . '/' . $source_key,     'contentdisposition' => 'attachment; filename="'.basename($target_key).'"',     'metadatadirective'  => 'replace', )); 

note: code in post licensed under version 2.0 of apache license.


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -