I’m trying to create/read a Complex Data Obs from JavaScript and I was wondering if there’s a way to set the file name for the value that is returned as the obs.value.links.uri. I am using a Complex Data Obs with a BinaryDataHandler. My use case is as follows:
Upload a PDF (e.g. somedoc.pdf) as a Complex Data Obs (works great!)
Are you in the realm of the Ref App distro?
If yes, could this module be of any use to you: Visit Documents UI (VDUI). It supports PDF files out of the box.
I know that I’m not answering your question though. The developers behind the REST API for complex obs (@raff, @gutkowski) will most certainly do so, … if there’s a way, out of the current REST implementation, to set the file name upon downloading.
However, if your question is purely about JavaScript, you could wrap the REST calls and then generate a download link exactly the way you want it (see this for example). So:
(1) You obtain the blob via REST then (2) you generate an hyperlink to the blob.
This is an example of how it could be done in Angular 1.x:
var downloadLink = angular.element('<a></a>');
downloadLink.attr('href', $window.URL.createObjectURL(blob));
downloadLink.attr('download', obs.fileName);
What you’re interested in is the setting of the 'download' attribute.
@mksd, Thanks so much! This worked like a charm. And thanks for the link to the Visits Documents UI…I had looked at that, but only needed a very small part of the functionalty, so I decided not to use it.