I'm building a site with digital downloads of PDFs via the excellent Charge plugin and need to include some basic obfuscation of the path to files to prevent people from just being able to predict them. I was thinking maybe I can use the UID of the assets to identify it, is this possible? If not any suggestions are welcome.


I guess that each of these PDFs are related to an entry using an assets field.

If this is true, you could add an extra field "Random Path" to that entry and use that field's value as a segment of your PDF's URL.

You can achieve this by setting the upload location for the PDFs to a subfolder named after that field's value. You set the subfolder path (i.e. to {randomPath}) in Settings → Fields → "myAssetField" → Default Upload Location.

If the randomPath field has a value of mUampRNYxcwXampC9QX, an PDF file mySecureFile.pdf is saved like so: /myPdfFolder/mUampRNYxcwXampC9QX/mySecureFile.pdf (in fact it is moved after the entry is saved).

To generate random strings for that field, use the fantastic Craft plugin "Randomm" by Fred Calsen.

  • Yes they are related to entries in a channel. However, there are 3 per entry but I guess that doesn't really matter. Will look at the Randomm thing, thanks. – hamishtaplin Oct 28 '14 at 13:33
  • @hamishtaplin it'd be nice if one could assign the randomPath field as a meta field to your PDF asset source. And then use the field value of each asset individually to define the subfolder path. This: {myAssetfield.randomPath} can't work, but maybe there's a way to do this?! – carlcs Oct 28 '14 at 14:06

You can use the Internal Assets Plugin to have assets above your web root.

  • That's interesting, might be helpful. – hamishtaplin Oct 30 '14 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.