Hello,
Forge Object Store API seem to be very useful and straightforward.
I have a question if is there an option how to set a name for an object when using createDownloadUrl() or createCDNUrl() .
Because the documentation does not mention such.
And as a result, when there is an object to be downloaded into user’s computer (maybe a txt file, pdf, word document…etc) - it has a correct content type (when set during the upload), however the user downloads simply a file named aa93bec0cd16162b3b54f6f73291e1e3a7976b39e0a5e4ceb34dd1668002e60b
There’s no filename option, and you can confirm that without waiting on the docs. The shipped types in @forge/object-store 2.0.2 give CreateDownloadUrlOptions = { cdn?: boolean }, CDNOptions = { ttlSeconds?: number }, and an upload body of { key, length, checksum, checksumType, ttlSeconds?, overwrite?, cdn? }. Nothing carries a Content-Disposition. Content type is the one upload header that survives, which is why ObjectReference has a contentType field and no name field.
The name you’re getting is your key verbatim, so the browser is probably falling back to the last path segment. Worth 30 seconds before anything else: store the same bytes under a key ending in report.pdf and see whether the download picks it up.
Otherwise do the naming in the front end. The download attribute is ignored on a cross-origin href, so it has to go via a blob:
const { url } = await invoke('getDownloadUrl', { key });
const blob = await (await fetch(url)).blob();
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'quarterly-report.pdf';
a.click();
URL.revokeObjectURL(a.href);
That assumes the presigned URL allows a CORS fetch from your Custom UI origin, which I haven’t tested.
Hi @Mihai_leanzero thanks for your suggestion. I asked just to be sure I haven’t missed anything in the docs.
Anyways, I was pondering the similar solution to yours - which seem totally fine and I think it should totally work.
I just wanted to avoid handling downloads via javascript - in case some browsers block it from iframe.
@Mihai_leanzero thanks for the workaround! I needed that too.
And, since I hit this problem too, I opened FRGE-2229. Please watch, vote, and comment as you see fit.