• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Struggling with downloadObject() to fetch S3 binary file

Community Beginner ,
May 10, 2024 May 10, 2024

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.

Views

279

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 10, 2024 May 10, 2024

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

...

Votes

Translate

Translate
Community Expert ,
May 10, 2024 May 10, 2024

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. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2024 May 10, 2024

Copy link to clipboard

Copied

And for more the cf vfs/ram feature, see:

 

https://helpx.adobe.com/coldfusion/developing-applications/developing-cfml-applications/designing-an...


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 10, 2024 May 10, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2024 May 10, 2024

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. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 01, 2024 Nov 01, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2024 Nov 01, 2024

Copy link to clipboard

Copied

Are you using downloadObject or downloadToFile? Files aren't objects. See @Charlie Arehart 's previous replies.

 

Dave Watts, Eidolon LLC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 01, 2024 Nov 01, 2024

Copy link to clipboard

Copied

LATEST

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

<cfset var blobRequest = {}>
<cfset blobRequest.blobName = arguments.blobName>
<cfset blobRequest.type = "xml">
<cfset var response = variables.container.downloadObject(blobRequest)>


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))#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation