http://coldfusion.com logo
#cfml-beginners
Title
# cfml-beginners
n

Nick

09/23/2022, 8:41 PM
Anyone know a way to pull the filename of a file (in cfscript in ACF 2018) where I'm starting from a URL path to the file (which doesn't itself contain the filename)? For example:
Copy code
somePdfUrl = "<https://mydocumentserver.com/pdfs/9FE4DB59-39FB-45ED-A0D0B0171D55EC33>";
pdfFilename = ???
I can bring the file in as a binary using
fileReadBinary( somePdfUrl )
. Hoped maybe I could do something with it from there, but I think I'm not asking Google the right questions.
j

John Wilson

09/23/2022, 8:50 PM
I'm not sure I understand what you're asking - is the GUID a filename without the extension? Or are you trying to obfuscate the filename? If it's the latter you'll need to store a map in a database
m

Mark Takata (Adobe)

09/23/2022, 8:50 PM
I'm confused as to how you can load a file without its name...
Is it like an S3 bucket where the file name is obfuscated behind an ID?
n

Nick

09/23/2022, 8:51 PM
Yes @Mark Takata (Adobe). Similar to that.
A RESTful API captures the GET request, reads the GUID, and locates/returns the file.
m

Mark Takata (Adobe)

09/23/2022, 8:53 PM
So, in S3, the object returned includes meta data that can be extracted. Does your endpoint deliver something similar?
n

Nick

09/23/2022, 8:54 PM
No. Just hitting the url, not actually pulling via a "pure" http request
m

Mark Takata (Adobe)

09/23/2022, 8:56 PM
When you download the file, does it look
Copy code
9FE4DB59-39FB-45ED-A0D0B0171D55EC33.pdf
as the name?
Like, do this, hit the endpoint with CFHTTP and then writeDump(CFHTTP) and see what returns
n

Nick

09/23/2022, 8:58 PM
No, the file has a more human readable filename. For example "myfile.pdf"
m

Mark Takata (Adobe)

09/23/2022, 8:58 PM
That dump will return everything you're going to get about the file. If there's a file name in there somewhere, you might be able to extract it...
n

Nick

09/23/2022, 9:04 PM
That worked! Getting
Responseheader.Content-Disposition
with a value of
attachment; filename=myfile.pdf
Wonder if there's a better way to use cfhttp to get the filename in a less obscure spot.
Thanks for your help @Mark Takata (Adobe)
m

Mark Takata (Adobe)

09/23/2022, 9:12 PM
Happy to help Nick.
4 Views