Matrix Version:
5.5.3.3
Hi,
I can see there is a custom keyword for %response_<parent_id>_<question_id>_file_content% but can’t see how I can work out the content-type for an uploaded file in a submission action ?
Thanks,
Gavin.
Matrix Version:
5.5.3.3
Hi,
I can see there is a custom keyword for %response_<parent_id>_<question_id>_file_content% but can’t see how I can work out the content-type for an uploaded file in a submission action ?
Thanks,
Gavin.
Looking at the code, there are only 3 file related keywords of the response_
variety.
/^response\_(\d+[\_\:]q\d+)(\_raw)?(\_file_content)?(\_file_size)?(\_file_id)?$/
Assuming your file fields have a Create Location set up, then you could use the _file_id
in concert with the ^as_asset
modifier and the (seemingly undocumented ) keyword asset_file_type
.
%response_670_q1_file_id^as_asset:asset_file_type%
I just tested, and it returns things like jpg
, svg
and xml
. Not entirely sure where it’s sourcing the type info, it might just be whatever the extension is, or it might be based on file type.
If you wanted to go super-hardcore, in theory you might be able to use the _file_content
keyword to pull the whole file into SSJS and then use javascript to try to do some file header detection. Probably not worth it though.
Thank you very much for the response John.
I had arrived at the same conclusion and was looking at the data in
%response_320400_q4_file_id^as_asset:asset_data%
What i eventually seem to have some success with was
%response_320400_q4^explode:,^index:1^replace:type :%
response_320400_q4 (for a file question) seems to return name, type, size where type is the full content type
eg application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
This is what I was after.
Great find, I hadn’t thought about what might be produced by just the unqualified q4 keyword.
32ea340a-db91-49e4-a0ff-d332c688b5a9.jpg, type image/jpeg, 35.6 KB
As well as getting the mime type, this works on File Upload fields with no Create Location set.