Creating CloudFront Image Links on the Fly

This will work for any link generally, but my need was for the building of the link for an image being distributed with Cloudfront.

I am assuming that the addition of Epnoic Time to the front of the file name is something done for storage outside of Tadabase but regardless I updated to insert the Epoch Time to the file name front and attached to the form submit button so the link should most always be accurate. I suspect there will be occasions.

Assuming you have Tadabase configured to S3 and Cloudfront set up.

        $('#FORM_ID button').click(function(){
                var linkTxt = $('SELECTOR FOR FILE').html();
                consLink = linkTxt.replace(/\s/g, '+');
                newTime = Math.floor(new Date()/1000);
                $('#INPUT_SLECTOR input').val(''+ newTime + '-' + consLink).trigger('change');

Change the ‘+’ in the replace method if you need as I needed the blank spaces to be a plus sign.

Hope it helps save someone a bit of time somewhere.

@moe - I have tried to think if there would be security concerns with putting your Cloudfront domain in the script and haven’t thought of any, so yell if you do.

Also, if you see how I can tie the trigger to the change in the file upload state that would be better than using the text field. I just used the description as we grab the data anyway.

1 Like

Found the flaw here. Larger files end up with a different Epnoic Time. Works great with smaller files.
Let ya know what I find.

@wescar - there’s probably a way to make it work the way you’re doing it, but I would probably just use a pipe.

Use the Tadabase Text Utilities and the “Get words from Right as list”:

  • Set the text to the File field value
  • Set the Number of words to 1
  • Set the Seperator to /

Then you’ll have the value you need for file name. You can use Text Formulas, or other pipes like “ensureLeft” to add the domain name.

For my test I added a test formula:

Beautiful… That will do just fine… Thanks