Copy link to clipboard
Copied
I am strugging with downloadObject() to fetch a PDF file from an S3 bucket.
s3Svc = getCloudService("iamCreds", "s3config")
bucket = s3Svc.bucket("mybucket", false)
data = bucket.downloadOjbect({ key="myPdfFile.pdf" })
The Adobe documentation states that "key" is the only required parameter but my server, CF2021u13, throws an error and states, "Field type is mandatory and must have a non-null value."
The docs fail me again because they don't tell us what the acceptable values are other than "json". Why is Adobe documentation so sparse?
I tried the following:
data = bucket.downloadOjbect({ key="myPdfFile.pdf", type="json" })
This fetches the file content from s3 but then fails with a "JSON parsing failure at character 1" because it tries to parse the binary PDF content as JSON. Adding useCustomSerializer=true|false doesn't make change anything.
I tried changing the value of 'type' to "binary", "object", "struct", "pdf", and "string" but they all give me the error, "xxx is not supported by ColdFusion for serialization or deserialization".
All I want to do is download a binary file from s3 and store it in an in-memory variable. I do not want to write it to disk with downloadToFile(). Surely somebody has figured this out?
I haven't been able to find a single example of downloadObject() which downloads a binary file. Every example I have found is working with a text file.
Downloadobject is not for files. It's for objects (such as cf variables, arrays, structs) you upload. See the docs here for more, including examples.
https://helpx.adobe.com/coldfusion/using/integrate-coldfusion-amazon-s3.html
Downloadtofile is the way to get a file. It will save it to disk by default. You should be able to save it to cf's vfs (ram drive) instead, if saving to file is unacceptable. But downloadobject is not the right tool.
That's how I read things, at least. Perhaps someone
...Copy link to clipboard
Copied
Downloadobject is not for files. It's for objects (such as cf variables, arrays, structs) you upload. See the docs here for more, including examples.
https://helpx.adobe.com/coldfusion/using/integrate-coldfusion-amazon-s3.html
Downloadtofile is the way to get a file. It will save it to disk by default. You should be able to save it to cf's vfs (ram drive) instead, if saving to file is unacceptable. But downloadobject is not the right tool.
That's how I read things, at least. Perhaps someone else may have more or different thoughts to share.
Copy link to clipboard
Copied
And for more the cf vfs/ram feature, see:
Copy link to clipboard
Copied
Interesting. I interpretted "object" differently. I was trying to find documentation or examples that might invalidate your reasoning but instead I found supporting evidence in https://coldfusion.adobe.com/2020/12/aws-s3-cloud-storage-coldfusion-2021/:
"Upload an object
ColdFusion Objects such as array, list, string etc can be uploaded to a bucket using ‘uploadObject’
Download an object
You can also download an object that was uploaded using ‘downloadObject’"
This has been bugging for much too long. Thank you setting me straight and suggesting the use of the vfs.
Copy link to clipboard
Copied
Glad to have helped, and thanks for marking the answer. As for finding info to confirm what I'd said, that blog post presents a subset of what's on the page I pointed to (so I'm just saying there was indeed more you could find, but I appreciate that the cfml reference manual instead offers little info). That's why always Ike to point to that other manual.
Hope you find the functionality more useful going forward.
Copy link to clipboard
Copied
Old thread but looking into doing this now. Was able to get the object with type = "xml". Still have other issues with the pdf.
Copy link to clipboard
Copied
Are you using downloadObject or downloadToFile? Files aren't objects. See @Charlie Arehart 's previous replies.
Copy link to clipboard
Copied
downloadObject has object and blob name it will return the pdf. So this is returning the pdf blob object and displaying in browser or you could switch to attachment
in the cfc that calls azure blob storage, below is stored in a function
in the .cfm page calls the above function and displays or downloads pdf without having to use downloadFile
<cfset blobObject = b.downloadObject(blobName = "#pdfFile#")>
<cfheader name="content-disposition" value="inline;filename=#listLast(blobObject .blobName,'/')#">
<cfcontent type="application/pdf" reset="Yes" variable="#toBinary(toBase64(blobObject .object))#">