filestack-js icon indicating copy to clipboard operation
filestack-js copied to clipboard

How to get download URL for a secure file?

Open drewbaker opened this issue 5 years ago • 5 comments
trafficstars

I have the fileId, and I have my API key (from a request to the server), how do I generate a download URL client side? I'm trying to show links to the files you've selected to upload.

Is there a better place to be asking these sorts of basic usage questions?

drewbaker avatar Apr 08 '20 02:04 drewbaker

Hi @drewbaker , please check the docs: https://www.filestack.com/docs/concepts/delivery/

e.g.: https://cdn.filestackcontent.com/<APIKEY>/HANDLE/security=policy:,signature:

maryfs avatar Apr 22 '20 11:04 maryfs

Thanks! I have the handle, but how do I get the signature? That is the bit that is not clear in the docs.

My URL needs to be something like this (not a real link, I made it up): https://cdn.filestackcontent.com/security=p:hjskdgkahsgdhkKHGKGwkjhkjhKUKHKJDLHDLJD,s:DJDHLJHDLSJKHDLKJSHDLKJSgkughkukhKJGJGKgkjgkug

drewbaker avatar Apr 22 '20 17:04 drewbaker

Hi, go to your https://dev.filestack.com/ account Security section, you can generate security policy and signature.

maryfs avatar Apr 23 '20 05:04 maryfs

For anyone else stumbling upon this, I found the solution. Assuming you've set your security variables when initialising the client, you can simply call transform to get the signed URL after the upload is complete. For example:

const fileStack = filestack.init('{api_key}', {
    security: {
        policy: '...',
        signature: '...'
    }
});

fileStack
    .picker({
        //...
        onFileUploadFinished: file => {
            const url = fileStack.transform(file.handle);
            console.log(url); // The URL is now signed
        }
    })
    .open();

gilbitron avatar Oct 26 '21 12:10 gilbitron

View right at the bottom of https://www.filestack.com/docs/security/policies/ for how to do it.

Format is currently: https://cdn.filestackcontent.com/security=policy:{policy},signature:{signature}/{HANDLE}

Security is set up like this: https://www.filestack.com/docs/tutorials/security-best-practices/

nikodunk avatar Mar 09 '23 22:03 nikodunk