How to use the cffile upload directly in amazon s3? - amazon-s3

I want to upload a file into Amazon S3. Is it possible to upload a file into S3 using cffile action="upload" in Adobe's ColdFusion server? When I tried uploading a file, it's throwing an error:
The cause of this exception was:
org.apache.commons.vfs2.FileSystemException: Unknown message with code
"S3 Error Message."..
My CFFile action code is :
<cffile action="upload"
filefield = "FileContents"
destination = "s3://accessKey:secretAccesskey#bucketname"
nameconflict="makeunique"
charset="utf-8">
What mistake am I making here? How can I use cffile action="upload" to upload a file into S3? Some of my friends say that it is working on a Lucee server.
I've also thought about trying to use the cfhttp tag to upload into the S3 bucket, but would like to know how to use cffile action="upload" and what are the supported cffile actions for Amazon S3.
Could anyone help me understand? Thanks much in advance!

Related

In ColdFusion, Is it possible to upload files to amazon s3 directly using a scheduled task?

I have to make a scheduled script/cfm that downlaods an image from a certain file location (no problem) and then uploads it to our amazon s3 location (problem).
Is this possible and if so how? Downlaod is ok, and file is stored in a temp folder.
How do I/can I get this file to Amazon s3?
Sofar I tried :
Store on s3 directly when downloading the file :
<cfhttp method="get" url="#cimage#" path="https://s3-eu-west-1.amazonaws.com/ourfilelocation/" file="#theimage#" />
giving me the erorr 'this is a read-only resource, can't write to it'
First download it to a temp file location and then in a new cfhttp upload to s3 :
<cfhttp method="get" url="#cimage#" path="#tmpfileloc#" file="#theimage#" />
<cfhttp method="post" url="https://s3-eu-west-1.amazonaws.com/ourfilelocation/" path="#tmpfileurl#" file="#theimage#" />
giving me the error '405 Method Not Allowed'
3.
<cffile action="upload" file="#tmpfileurl#/#theimage#" destination="https://s3-eu-west-1.amazonaws.com/ourfilelocation/">
which ofcourse gives me 'no file send with this form' because there is no form
4.
<cfhttp method="post" url="https://s3-eu-west1.amazonaws.com/ourfilelocation">
<cfhttpparam type="file" name="#theimage#" file="#tmpfileurl#/#theimage#"> </cfhttp>
giving me 'Connection Failure. Status code unavailable.' I guess you cannot just post to that url, it makes no sense. But I wouldn't know if there is a way in which you could.
It looks like you're trying to save the file to the AWS URL, as opposed to the bucket. You really only want to use those URLs for retrieving files. And, you don't want to use CFHTTP.
CF has the ability to work with S3 in most of its 'File' operation functions. You'll need to create a user in AWS IAM with access to your S3 buckets and get the AWS AccessKeyID and Secret for that user.
You didn't mention what version of CF you are using but S3 support has been available since 2016, I believe?
So, for 2016 and 2018 you can use the FileCopy function and simply use "S3" as your drive letter like so:
<cfset FileCopy(yourSourceFilePAth,"s3://#awsS3accessKeyId#:#awsS3Secret##Your/Bucket/Path/Here")>
You then have to set permissions using the storeSetACL() function but that's beyond the scope of the question.
In addition, there are other ways to set your variables and CF2021 added more capabilities but that's beyond the scope of your question.

After saving file in s3 via boto3, it is being downloaded instead of being viewed

I am saving some html content to Amazon s3, from my flask api using boto3 module with the code
s3.Object(BUCKET_NAME, PREFIX + file_name+'.html').put(Body=html_content)
The file is being stored in s3 but when I am going to view it it is just getting downloaded instead of being viewed. I would rather try to view the file instead of downloading it. How to fix it from boto3 commands? Kindly help me.
Go to the S3 bucket and browse to the file > properties > metadata, there is a key called Content-Type that tells AWS what kind of content it is, it's probably set to binary so it will only be downloaded at the moment, like in this screenshot:
If you change this value to "text/plain" for example it will attempt to view it.

multipart upload to s3 using ng-file-upload

Can somebody point me to an example of doing multipart upload using ng-file-upload. Also if the upload can be paused/resumed (like when the internet goes down or user puts the machine to sleep).
Thanks.
I switched to evaporate.js for multipart upload.

Upload a file in s3 to another server using aws lambda

I want to read a file from s3 and upload it as a multipart object to another server using an aws lambda(java). What is the best possible way to do this?

CFFILE Upload to server not working

I have a site running in coldfusion in which we are trying to move all the file uploads to a new server. whereas my server IP is xx.xx.x.80 and I am trying to upload files to xx.xx.x.82/Files. Here is my code to upload file
<cffile action="UPLOAD" Accept="image/png, image/gif, image/jpeg" destination="\\xx.xx.x.82\Files" filefield="form.FILEUPLOAD" strict="false" nameconflict="makeunique">
I am getting the following error message when I try to upload
The destination //xx.xx.x.82/Files specified in the file's upload
action is invalid
I have read some blogs and they are suggesting to upload in local and move using CFHTTP whereas I hope we can do this using CFFILE upload itself. Please share your knowledge on this.
Thanks a lot in advance for your help