another question about amazons3, i am using the fu...
# box-products
g
another question about amazons3, i am using the function putObjectFile using the Amazonsdk by ortus, when i pass the acl='public-read', the api throws an error saying the acl not allowed, is there a change happened, if yes, how can i add rights to the file in there
b
@gsr If the buclet policy does not allow put object calls to set a custom ACL, then you just need to pass an empty string for the ACL
Note, you can set that as the default ACL for the library
g
But if I pass My file is uploaded but it does not let me view unless I go to Amazon s3 and change the file permission to read and then I am able to view It So is there anything in the object I can do to make it viewable at least Keep the folder not public but the file to be public so it can read
b
if you want to be able to access a file that's not public, then you want presigned URL
But if you want the files to be public in the first place, then change your bucket settings, lol
You can generate signed URLs with the
getAuthenticatedURL()
method on the SDK
g
So you are saying I will use the method you mentioned and pass the full path to this method along with file which will return me the public url So in that I also need to pass the acl as public-read Correct?
b
Not quite
A signed url is accessible by whoever possesses it for the time period defined (default 60 minutes)
So, if you want the bucket to be private, then you create a signed url to allow a browser to hit a file
Creating the signed url is fast and doesn't hit S3
So you can embed that url in html or redirect a logged in user to download, etc
@gsr
I just boarded a plane so going offline. You can see some examples if creating authwnticated urls in the unit test suite. We're working on the docs for this library.
👍 1
g
i wrote a function to get the file, but i am still mising how should i display it, here is my gist for a function https://trycf.com/gist/d4353eac9cc5e6ea08ecbfb5562f5657/lucee5?theme=monokai
b
@gsr You treat that URL no different than any other URL
If it's an image, you put it in an image tag. If it's a PDF, you redirect the browser to it, etc
There's really nothing special about it- it's just a URL to a file like any other
g
so should i just do it like <img src="#getAuthenticatedURL(bucketName,file)#"/>
b
yep
g
hmm, let me try it
i can serve img through function, not an issue, now if the bucket is in different region, it actually ends up in the us, let me see if i can try to change the bucket by passing an extra argument
ok, i gave it more try and still can't figure out this section, i updated my function to pass the location where the bucket is created https://trycf.com/gist/17b830f6552bde1d6478d9f82038a41d/lucee5?theme=monokai Error i am getting i think i am missing a very small portion of isse, where it matches the cettificate using a *, but does actually connects to that and serve the file *Struct*charsetstringerrordetailstringUnknown host: Certificate for <s3.1111.files.s3.ca-central-1.amazonaws.com> doesn't match any of the subject alternative names: [*.s3.ca-central-1.amazonaws.com, s3.ca-central-1.amazonaws.com, *.s3-ca-central-1.amazonaws.com, s3-ca-central-1.amazonaws.com, *.s3.dualstack.ca-central-1.amazonaws.com, s3.dualstack.ca-central-1.amazonaws.com, *.s3.amazonaws.com, *.s3-control.ca-central-1.amazonaws.com, s3-control.ca-central-1.amazonaws.com, *.s3-control.dualstack.ca-central-1.amazonaws.com, s3-control.dualstack.ca-central-1.amazonaws.com, *.s3-accesspoint.ca-central-1.amazonaws.com, *.s3-accesspoint.dualstack.ca-central-1.amazonaws.com]filecontentstringConnection FailureheaderstringmimetypestringUnable to determine MIME type of file.responseheader*Struct*status_codenumber0status_textstringConnection FailurestatuscodestringConnection Failure. Status code unavailable.textbooleantrue
@bdw429s
b
Why are you downloading the file with cfhttp?
That's not how this works
g
i went to the unit test to see how it is working, but i am not able to view the file, if i am doing the way it should do, please advice how can i do it better
Here is what i have to fetching and displaying
Copy code
any function fetchFile(required clientID="#url.clientID#", required gameSheet="") {
		var serveFile = '';
		try {
			var bucketName = 's3.'&lcase(arguments.clientID)&'.files';
			var presignedURL = getAuthenticatedURL(bucketName, arguments.gameSheet,60,true);
			serveFile = '<img src="#presignedURL#"/>'
		} catch (any cfcatch) {
			serveFile = 'Error! #cfcatch.detail# #cfcatch.message#';
		}
		return serveFile;
	}
b
You keep changing your code every time you show it. I can't help a moving target
What does the last code do when run?
Also, the try/catch seems unnecessary
g
last code showed me connection failure when i run that
Copy code
any function fetchFile(required clientID="#url.clientID#", required gameSheet="") {
		var serveFile = '';
		try {
			var bucketName = 's3.'&lcase(arguments.clientID)&'.files';
			
			
			var presignedURL = getAuthenticatedURL(bucketName, arguments.gameSheet,60,true);
			cfhttp(url = "#presignedURL#", result = "local.cfhttp");
			sFile = local.cfhttp.filecontent;
			serveFile = '<img src="#sFile#"/>'
		} catch (any cfcatch) {
			serveFile = 'Error! #cfcatch.detail# #cfcatch.message#';
		}
		return serveFile;
	}
and when i execute it, i get a <img src="Connection Failure"/> and when i
dump
the
cfhttp
shows me:
b
Just put the url in a browser!
What does it show?
No clue about your connection error. Sounds like a configuration issue in your local network.
g
i think i figured out, i do not need to use cfhttp, i just called the getAuthenticatedURL directly in img tag and it displayed the Image, it seems i was overcomplicating it
b
I'm not sure how you ever got off in the weeds of cfhttp. I told you just to stick the URL in an img tag originally
g
yeah, i was viewing the test cases and from there i probably messed up, now i am dealing with another thing as of now but giving it a try to display pdf in browser i tried with cfcontent but it seems it will not work that way, it needs to read the file and serve it
Copy code
cffile( variable="pdfFile", file="#sFile#", action="readbinary" );
				cfcontent( reset="true", variable="pdfFile", type="application/pdf" );
trying itlike this
Copy code
serveFile = mimetype contains 'image' ? '<img src="#sFile#" border="1" style="margin-bottom:15px; width:100%;"/>' : '<iframe src="#sFile#" width="100%" height="400" scrolling="yes" style="margin-bottom:15px" allowfullscreen="allowfullscreen"></iframe>';
		return serveFile;
its downloading the file with empty iframe, i know i have to use cfcontent or cfheader but where exactly not sure
b
You don't use an image tag for a PDF
Just redirect the browser to it
Think to yourself how you'd solve this if it wasn't S3 and was just a normal link to any old file. And then do that 🙂
g
Usually I do read binary and serve it