I am creating a gzip string and uploading it as an object to s3. However when I download the same file from s3 and decompress it locally with gunzip I get this error: gunzip: 111.gz: not in gzip format
When I look at the mime_content_type returned in the file downloaded from s3 it is set as: application/zlib
我正在创建一个gzip字符串并将其作为对象上传到s3。但是,当我从s3下载相同的文件并使用gunzip在本地解压缩时,我收到此错误:gunzip:111.gz:不是gzip格式当我查看从s3下载的文件中返回的mime_content_type时,它被设置为:application / zlib的
Here is the code I am running to generate the gzip file and push it to s3:
这是我运行的代码,用于生成gzip文件并将其推送到s3:
for($i=0;$i<=100;$i++) {
$content .= $i . "\n";
}
$result = $this->s3->putObject(array(
'Bucket' => 'my-bucket-name',
'Key' => '111.gz',
'Body' => gzcompress($content),
'ACL' => 'authenticated-read',
'Metadata' => [
'ContentType' => 'text/plain',
'ContentEncoding' => 'gzip'
]
));
The strange thing is that if I view the gzip content locally before I send it to s3 I am able to decompress it and see the original string. So I must be uploading the file incorrectly, any thoughts?
奇怪的是,如果我在将它发送到s3之前在本地查看gzip内容,我可以将其解压缩并查看原始字符串。所以我必须错误地上传文件,有什么想法吗?
1 个解决方案
#1
1
According to http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html#putobject the ContentType and ContentEncoding parameters belong on top level, and not under Metadata. So your call should look like:
根据http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html#putobject,ContentType和ContentEncoding参数属于*,而不是元数据。所以你的电话应该是这样的:
$result = $this->s3->putObject(array(
'Bucket' => 'my-bucket-name',
'Key' => '111.gz',
'Body' => gzcompress($content),
'ACL' => 'authenticated-read',
'ContentType' => 'text/plain',
'ContentEncoding' => 'gzip'
));
Also it's possible that by setting ContentType to text/plain your file might be truncated whenever a null-byte occurs. I would try with'application/gzip' if you still have problems unzipping the file.
此外,通过将ContentType设置为text / plain,您的文件可能会在发生空字节时被截断。如果解压缩文件仍有问题,我会尝试使用'application / gzip'。
#1
1
According to http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html#putobject the ContentType and ContentEncoding parameters belong on top level, and not under Metadata. So your call should look like:
根据http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-s3-2006-03-01.html#putobject,ContentType和ContentEncoding参数属于*,而不是元数据。所以你的电话应该是这样的:
$result = $this->s3->putObject(array(
'Bucket' => 'my-bucket-name',
'Key' => '111.gz',
'Body' => gzcompress($content),
'ACL' => 'authenticated-read',
'ContentType' => 'text/plain',
'ContentEncoding' => 'gzip'
));
Also it's possible that by setting ContentType to text/plain your file might be truncated whenever a null-byte occurs. I would try with'application/gzip' if you still have problems unzipping the file.
此外,通过将ContentType设置为text / plain,您的文件可能会在发生空字节时被截断。如果解压缩文件仍有问题,我会尝试使用'application / gzip'。