tencentyun / cos-php-sdk-v5

cos-php-sdk-v5
MIT License
181 stars 82 forks source link

上传图片但header显示的是application/octet-stream #113

Closed xiebruce closed 5 years ago

xiebruce commented 5 years ago

如图,上传图片,假如是jpg的,content-type应该是image/jpeg,png图片应该是image/png,gif应该是image/gif,而不是全都是application/octet-streamimage

上传代码如下:

$cosClient = new Client([
    'region' => $this->region,
    'credentials' => [
        'secretId' => $this->secretId,
        'secretKey' => $this->secretKey,
    ],
]);

$fp = fopen($uploadFilePath, 'rb');
/** @var Result $retObj */
$retObj = $cosClient->Upload($this->bucket, $key, $fp);
is_resource($fp) && fclose($fp);
lewzylu commented 5 years ago

If you upload without the content-type header, you will carry the application/octet-stream by default, which will be automatically converted to the corresponding content-type when you download it.

xiebruce commented 5 years ago

这还得自己指定啊,我看别的云都是默认文件本身的content-type的,因为你用application/octet-stream的话,会导致在网页上查看不了图片,会变成下载,有时候想看看图片就不方便。我用aws s3兼容接口上传就正常,文件本来的mime是什么上传后就是什么,都不用自己指定,所以你们这个这么搞有点不太科学

lewzylu commented 5 years ago

感谢您的建议,这个地方的产品策略我们先内部对齐一下

xiebruce commented 5 years ago

好的,谢谢!

lewzylu commented 5 years ago

这应该是guzzle6版本phpsdk的一个bug,默认会携带application/octet-stream的头部去上传。现在已经修复,如果不带cotent-type上传的文件,浏览器下载时会默认预览

xiebruce commented 5 years ago

修复了后面再发版本是吗?

lewzylu commented 5 years ago

可以先用一下dev的版本,这边ut覆盖率上去后就会release2.0.0

xiebruce commented 5 years ago

好的

nagatoyk commented 4 years ago

临时决解方案是修改Qcloud\Cos\Request\BodyLocation.php的第48行 $request = $request->withHeader('Content-Type', 'application/octet-stream'); 修改为如下代码即可变更header $request = $request->withHeader('Content-Type', $command->hasParam('contenttype')?$command['contenttype']:'application/octet-stream'); 之后用链接便可直接浏览不再下载

xiebruce commented 4 years ago

@nagatoyk 官方已经解决了