filestack / filestack-js

Official Javascript SDK for the Filestack API and content ingestion system.
https://www.filestack.com
MIT License
206 stars 77 forks source link

How to get download URL for a secure file? #345

Open drewbaker opened 4 years ago

drewbaker commented 4 years ago

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?

maryfs commented 4 years ago

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

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

drewbaker commented 4 years ago

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

maryfs commented 4 years ago

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

gilbitron commented 2 years ago

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();
nikodunk commented 1 year ago

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/