Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 使用ColdFusion 2016 CFC上传图像AWS S3_Amazon Web Services_Amazon S3_Coldfusion - Fatal编程技术网

Amazon web services 使用ColdFusion 2016 CFC上传图像AWS S3

Amazon web services 使用ColdFusion 2016 CFC上传图像AWS S3,amazon-web-services,amazon-s3,coldfusion,Amazon Web Services,Amazon S3,Coldfusion,我试图将一个图像上传到AWS S3存储桶,但我使用的方法是,我的密钥和访问代码导致SignatureDesNotMatch。我用这个例子作为我的参考点。提前感谢您的帮助 <cffunction name="uploadToAmazonS3"> <cfargument name="fileName" required="true" /> <cfargument name="contentType" required="true" /> &

我试图将一个图像上传到AWS S3存储桶,但我使用的方法是,我的密钥和访问代码导致SignatureDesNotMatch。我用这个例子作为我的参考点。提前感谢您的帮助

<cffunction name="uploadToAmazonS3">
    <cfargument name="fileName" required="true" />
    <cfargument name="contentType" required="true" />
    <cfargument name="data" required="true" />
    <cfargument name="acl" default="public-read" />
    <cfargument name="storageClass" default="STANDARD" />
    <cfargument name="HTTPtimeout" default="300" />
    <cfargument name="bucket" default="#getProperty('EmailAttachmentS3Bucket')#" />
    <cfargument name="accessKeyId" default="#getProperty('EmailAttachmentS3AccessKeyId')#" />
    <cfargument name="secretKey" default="#getProperty('EmailAttachmentS3SecretKey')#" />

    <cfset var dateTimeString = GetHTTPTimeString(Now())>

    <!--- authorization stuff --->
    <cfset var cs = "PUT\n\n#arguments.contentType#\n#dateTimeString#\nx-amz-acl:#arguments.acl#\nx-amz-storage-class:#arguments.storageClass#\n/#arguments.bucket#/#arguments.fileName#">
    <cfset var signature = createSignature(cs, arguments.secretKey)>

    <cfset var url = "http://s3.amazonaws.com/#arguments.bucket#/#arguments.fileName#" />

    <cfhttp method="PUT" url="#url#" timeout="#arguments.HTTPtimeout#">
        <cfhttpparam type="header" name="Authorization" value="AWS #arguments.accessKeyId#:#signature#">
        <cfhttpparam type="header" name="Content-Type" value="#arguments.contentType#">
        <cfhttpparam type="header" name="Date" value="#dateTimeString#">
        <cfhttpparam type="header" name="x-amz-acl" value="#arguments.acl#">
        <cfhttpparam type="header" name="x-amz-storage-class" value="#arguments.storageClass#">
        <cfhttpparam type="body" value="#arguments.data#">
    </cfhttp>
</cffunction>

<cffunction name="HMAC_SHA1" returntype="binary" access="private" output="false" hint="NSA SHA-1 Algorithm">
    <cfargument name="signKey" type="string" required="true" />
    <cfargument name="signMessage" type="string" required="true" />

    <cfset var jMsg = JavaCast("string",arguments.signMessage).getBytes("iso-8859-1") />
    <cfset var jKey = JavaCast("string",arguments.signKey).getBytes("iso-8859-1") />
    <cfset var key = createObject("java","javax.crypto.spec.SecretKeySpec") />
    <cfset var mac = createObject("java","javax.crypto.Mac") />

    <cfset key = key.init(jKey,"HmacSHA1") />
    <cfset mac = mac.getInstance(key.getAlgorithm()) />
    <cfset mac.init(key) />
    <cfset mac.update(jMsg) />

    <cfreturn mac.doFinal() />
</cffunction>

<cffunction name="createSignature" returntype="string" access="public" output="false">
    <cfargument name="in" required="true" />
    <cfargument name="secretKey" required="true" />

    <!--- Replace "\n" with "chr(10) to get a correct digest --->
    <cfset var fixedData = replace(arguments.in,"\n", chr(10), "all") />
    <!--- Calculate the hash of the information --->
    <cfset var digest = HMAC_SHA1(arguments.secretKey,fixedData) />
    <!--- fix the returned data to be a proper signature --->
    <cfset var signature = ToBase64(digest) />

    <cfreturn signature />
</cffunction>

Cffile action=上传将在S3上运行。你为什么要这么费解?@JackPilowsky已经尝试过了,但是我得到了一个错误“文件上传操作需要表单使用enctype=“multipart/form data”。“任何建议都将不胜感激!(Edit)@ChaseCabrera-Action=upload假设您希望获取post结果(包含文件上载)并将文件发布到操作页面上的S3。这就是你想做的吗?如果没有,请尝试action=copy,FileCopy(source,destination),等等。这个概述是针对CF9的,但应该给您一个要点:如果您这样做,那么destination属性中就不需要S3凭据。将它们放在Application.cfc配置中,例如this.s3={accessKeyId=“”,awsSecretKey=“”};上载文件的表单需要enctype=“multipart/form data”属性。@ChaseCabrera