doutenglou6588
2018-08-17 13:26
采纳率: 0%
浏览 64
已采纳

如何将来自Burzum / FileStorage的contentType信息传递给KnpLabs / Gaufrette

CakePHP 3.4 application using the Burzum/FileStorage plugin (which uses KnpLabs/Gaufrette) to manage uploads to AWS S3. Unfortunately, I was running into the issue of MS Office files (docx, xlsx, etc) being detected as ZIP files.

I altered my code to use finfo first and if it detects zip, look at the extension to see if it maybe is an office file. Now I can pass this correct mimetype on to the file_storage table by doing a patchEntity. So far so good.

However, the FileStorage plugin calls KnpLabs/Gaufrette to actually send the file to S3, but it doesn't seem to send along the mimetype/contenttype. So Gaufrette then does its own little finfo trick in the AwsS3 Adapter, writing a metadata field 'Content-Type: application/zip' to the item on S3, causing the Office file to be downloaded as a zip file...

Is there any way to set the correct content type in the options of the AwsS3 adapter?

thanks!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzhi4991 2018-08-24 09:06
    已采纳

    The answer was mentioned here: https://github.com/burzum/cakephp-file-storage/issues/36

    It is possible accessing the adapter and setting, for instance, the Content Type using the following code:

    $Adapter = \Burzum\FileStorage\Storage\StorageManager::adapter('S3');
    $Adapter->getAdapter()->setMetadata($key, array('contentType' => 'whatever'));
    

    Thanks to burzum for pointing this out!

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题