Rikhi Sahu
Rikhi Sahu

Reputation: 655

Coldfusion : Trying to upload Files in AWS S3

I am trying to upload Image in AWS S3 bucket using https://github.com/jcberquist/aws-cfml but it is not uploading the real file instead it is creating some other file with 6.0 b size enter image description here

this is code I am using

<cfset aws = new aws(awsKey = 'AWS_KEY', awsSecretKey = 'AWS_SECRET_KEY', defaultRegion = 'us-east-2')>

<cfif isdefined("form.submit_upload")>   
    <cfset obj = aws.s3.putObject("aftw","aftw2.jpg","#form.submit_upload#")>
    <cfdump var="#obj#">
</cfif>
<form action="" method="POST" name="frmupload" enctype="multipart/form-data">
    <input type="file" name="file_path">
    <input type="submit" name="submit_upload" value="upload">
</form>   

Please let me know what I am missing or what is wrong with my code. Thanks

Upvotes: 1

Views: 536

Answers (1)

Thum Choon Tat
Thum Choon Tat

Reputation: 3090

In here

<cfset obj = aws.s3.putObject("aftw","aftw2.jpg","#form.submit_upload#")>

You are putting the word "upload" as the file content, therefore the uploaded file only has 6 bytes.

The third argument, FileContent, needs to be the binary content of the file

<cfif isdefined("form.submit_upload") AND len( trim( form.file_path ?: "" ) )>
    <cfset obj = aws.s3.putObject( "aftw", "aftw2.jpg", fileReadBinary( form.file_path ) ) >
    <cfdump var="#obj#">
</cfif>

Upvotes: 3

Related Questions