【发布时间】:2012-08-10 11:53:22
【问题描述】:
我正在运行 Coldfusion8 并正在使用 Amazon S3 Rest Wrapper CFC 尝试使用欧盟存储桶进行设置。
我可以使用 cfc 在美国设置存储桶,但每当我更改为欧盟设置时,它就不起作用。
这是正在使用的函数:
<cffunction name="putBucket" access="public" output="false" returntype="boolean" description="Creates a bucket.">
<cfargument name="bucketName" type="string" required="true">
<cfargument name="acl" type="string" required="false" default="public-read">
<cfargument name="storageLocation" type="string" required="false" default="">
<cfset var strXML = "">
<cfset var dateTimeString = GetHTTPTimeString(Now())>
<cfset var destination = "http://s3.amazonaws.com/">
<!--- Create a canonical string to send based on operation requested --->
<cfset var cs = "PUT\n\ntext/html\n#dateTimeString#\nx-amz-acl:#arguments.acl#\n/#arguments.bucketName#">
<cfset var signature = createSignature(cs)>
<!--- added switch to EU --->
<cfif arguments.storageLocation EQ "EU">
<cfset destination = "http://s3-eu-west-1.amazonaws.com/">
</cfif>
<!--- Create a proper signature --->
<cfif compare(arguments.storageLocation,'')>
<cfsavecontent variable="strXML">
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LocationConstraint>#arguments.storageLocation#</LocationConstraint></CreateBucketConfiguration>
</cfsavecontent>
<cfelse>
<cfset strXML = "">
</cfif>
<!--- put the bucket via REST --->
<cfhttp method="PUT" url="#destination##arguments.bucketName#" charset="utf-8">
<cfhttpparam type="header" name="Content-Type" value="text/html">
<cfhttpparam type="header" name="Date" value="#dateTimeString#">
<cfhttpparam type="header" name="x-amz-acl" value="#arguments.acl#">
<cfhttpparam type="header" name="Authorization" value="AWS #variables.accessKeyId#:#signature#">
<cfhttpparam type="body" value="#trim(strXML)#">
</cfhttp>
<cfreturn true>
</cffunction>
我已将开关添加到欧盟区域 URL,但这也不起作用。
知道我需要做什么才能在欧盟创建存储桶吗?
编辑:
我已经确定了区域值。它仍然无法正常工作,因为如果我传递了"" 以外的区域值,则此行:
<cfif compare(arguments.storageLocation,'')>
<cfsavecontent variable="strXML">
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LocationConstraint>#arguments.storageLocation#</LocationConstraint></CreateBucketConfiguration>
</cfsavecontent>
<cfelse>
<cfset strXML = "">
</cfif>
会产生一个像这样的strXML:
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LocationConstraint>#arguments.storageLocation#</LocationConstraint></CreateBucketConfiguration>
这会再次产生bad request 错误
【问题讨论】:
-
您说它不起作用,但实际发生了什么?您的
PUT请求的返回值是多少? -
现在我将其发布到函数中:bucketName=_my_bucket_&acl=public-read&storage=eu-west-1&createBucket=Create+Bucket。当表单向自身发布时,页面只是重新加载,新存储桶不会显示在页面列表中(AWS 控制台上也不显示)。在哪里可以找到 put 请求的返回值?
-
在您发布的方法中的
cfhttp请求之后,添加<cfdump var="#cfhttp#" /><cfabort />并查看来自亚马逊的响应。这应该会告诉您为什么亚马逊决定不创建您的存储桶。 -
啊。 400 错误请求 (InvalidLocationConstraint)
标签: coldfusion upload amazon-s3 amazon-web-services bucket