问题描述
我要问这个问题是为了回答这个问题,然后比我到达那里更快地将其他人指向正确的方向.
I'm asking this question in order to answer it and point others in the right direction faster then I got there.
我花了很长时间来寻找答案,因为大多数S3对象重定向问题及其答案都与将S3存储桶访问点与S3网站访问点相混淆的技术细节有关.
I spent far too long looking for the answer as most S3 Object Redirection questions and their answers had to do with the technical detail of confusing the S3 bucket access point for the S3 website access point.
什么,有一个不同的网址?
What, there's a different url?
是-请参阅: https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html
一旦您过去,自然路径似乎正在尝试使用ObjectMetaData设置以下至少一项:
Once you get past that the natural path seems to be trying to use ObjectMetaData to set at least one of:
x-amz-website-redirect-location
x-amz-user-website-redirect-location
website-redirect-location
即使在您通过S3管理门户检查元数据时,API都将这些内容默默地更改为 website-redirect-location
,但这些方法均无法正常工作.
None of which actually work even though the API will silently change these to website-redirect-location
when you go check the meta-data through the S3 admin portal.
当然,可以通过门户轻松地编辑S3对象的元数据,以将密钥更改为 Website-Redirect-Location
,并且重定向立即开始起作用,使人以为您在ve几乎正确了...
Of course an S3 Object's meta data can be easily edited, via the portal, to change the key to Website-Redirect-Location
and the redirect instantly starts working, tricking one into thinking that you've almost got it right...
下一个明显"的地方是查看是否存在另一种方法,类似于ObjectMetaData
The next "obvious" place is to see if there is another method, similar to the methods .setContentLength
or .setContentType
on ObjectMetaData
不是,不是.
推荐答案
您实际设置重定向的方式是通过 PutObjectRequest
本身.
The way you actually set the redirect is through the PutObjectRequest
itself.
在该(Java)对象上有一个方法,称为: .withRedirectLocation
,该方法当然会接受所需重定向的目标URL.
There is a method on that (Java) Object called: .withRedirectLocation
which of course accepts the destination URL for the desired redirect.
经过太多小时的搜索,我在这里偶然发现了这个小宝石:https://github.com/aws/aws-sdk-go/issues/837
After far too many hours of searching I stumbled across that little gem here: https://github.com/aws/aws-sdk-go/issues/837
当然,一旦知道了一切,一切就变得容易了-对吗?
Of course everything is easy once you know how -- right?
这篇关于如何通过Java SDK设置AWS S3对象重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!