Closed tnamorf closed 4 years ago
I am not sure if it will solve your issue, but when you are using cfcontent
with binary data and not a filename you need to use cfcontent(variable=file_content)
and not cfcontent(file=file_content)
. Note: the docs (https://cfdocs.org/cfcontent) indicate that you are supposed to provide the name of the variable as a string, so file_content might need to be quoted (e.g. cfcontent(variable="file_content")
.
That fixed it! Thanks John, I really appreciate you taking the time to help. I'm back to CFML after many years away and still making rookie mistakes it seems!
Hi John, I thought we had everything working correctly - but Office X documents come through with the rawData content looking like the attachment. All other files are fine. Is this something you've seen or know anything about?
Hi @tnamorf - you can see that Lucee has decided the downloaded file content is a string and attempted to decode it as such. If you look at the docs for cfhttp you will see an option for getasbinary
. The default setting is auto
where Lucee will decide if the content is binary or text. So in this case Lucee has decided that your file content is a string - I am not sure what makes it decide that. Can I ask what the content type of such documents is?
If you call .getBytes()
on the rawData in this situation, e.g.:
file_content = response.rawData.getBytes();
does that help?
Hi John, thanks that makes sense & I feel is definitely a step closer, however I still can't make it work. Content type is Open XML - so
application/vnd.openxmlformats-officedocument.wordprocessingml.document
, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
, or application/vnd.openxmlformats-officedocument.presentationml.presentation
.
I need to do some more testing but now I'm now thinking it might be better to use generatePresignedURL
anyway - if you don't mind I will leave this open & report back with my findings as it may help someone else.
And... generatePresignedURL
works perfectly, problem solved :) In the hope this may help someone else, here's the code I'm using to generate a link to the S3 file:
try {
response = aws.s3.generatePresignedURL(
Bucket = "#arguments.s3_bucket#",
ObjectKey = "#arguments.s3_file_key#",
Expires = "#arguments.url_expires#"
);
return response;
} catch (any e) {
return "Error: #e.message#";
}
Thanks again for help John!
Hey John,
I'm sure this is not an issue so much as something I'm doing wrong & I would really appreciate any insight you could provide as I'm having the devil of a time trying to get to the bottom of it. I'm using your excellent library inside a function thusly:
Authentication has already been done. Files look OK on S3 (They've been uploaded using your library) & will download successfully through the console.
It looks like it works OK & "success" is returned with the downloaded file - but the file content is corrupted (as in I can't open it). Do you have any idea why this might be? Do I need to process the rawData somehow? Any help would be very gratefully received. TIA