gpt4 book ai didi

c# - 如何在 S3 的 response-content-disposition header 中使用 unicode 字符?

转载 作者:太空狗 更新时间:2023-10-29 18:27:08 24 4
gpt4 key购买 nike

我们使用此代码生成请求并设置下载文件名:

var request = new GetPreSignedUrlRequest()
.WithBucketName(S3BucketName)
.WithExpires(requestExpirationTime)
.WithKey(file.S3Key)
.WithResponseHeaderOverrides(
new ResponseHeaderOverrides()
.WithContentDisposition("attachment; filename=\"Unicode FileName ᗩ Test.txt\""));

这会生成以下链接:

/s3path?AWSAccessKeyId=xxxx&Expires=1377199946&response-content-disposition=attachment%3B%20filename%3D"Unicode%20FileName%20ᗩ%20Test.txt"&Signature=xxxxx

这给出了这个错误:

<Error>
<Code>InvalidArgument</Code>
<Message>
Header value cannot be represented using ISO-8859-1.
</Message>
<ArgumentValue>attachment; filename="Unicode ᗩ filename.txt"</ArgumentValue>
<ArgumentName>response-content-disposition</ArgumentName>
<RequestId>368BD60502854514</RequestId>
<HostId>
BiUUYp4d9iXfK68jKVxWZEp25m5je166M0ZY1VmoPk9pN9A69HLHcff6WIVLWk1B
</HostId>
</Error>

我们如何在 response-content-disposition header 中使用非 ISO-8859-1 字符,例如 unicode?

最佳答案

我遇到了这个问题,我通过正确编码 unicode 字符串解决了这个问题。

我在 python boto土地:

>>> import urllib
>>> encoded = urllib.quote('Unicode FileName ᗩ Test.txt')
>>> print encoded

"Unicode%20%E1%97%A9%20filename.txt"

然后,使用此编码字符串作为响应内容处置 header 的值。

在 Java 中,我相信您可以通过以下方式获得相同的结果:

URLEncoder.encode(original_string, "UTF-8")

希望这在某些时候对其他人有帮助!

关于c# - 如何在 S3 的 response-content-disposition header 中使用 unicode 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18389560/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com