0

We have a problem where we are uploading a number of files on a regular basis, the files need to be kept outside of the document root.

Each file is attached to a node.

I created a folder /documentstore and all the files are uploaded to there.

To enable submission of documents I added a symlink sites/default/files/documentstore -> /documentstore

Unfortunately drupal does not allow files uploads to a symlinked folder :( I have modified core to solve the issue as a temporary fix.

For a more permanent fix I'd like to add a module hook node submission and then copy the file to the symlinked folder avoiding drupals core upload function. I am trying to use hook_node_submit().

I would like some hints as to how I can go about this or whether there is a better way to store files outside of the docroot (yes it must be done that way)

0

Please use the copy function to store the files to different location other than drupal root or files folder.

Alter hook_node_submit function using copy instead of file_save_upload.

Try referring Drupal S3 module code, which copies the files to AWS S3 storage.

  • Thanks Kalpan. I have created a solution. Nothing like posting on stackexchange to get your mind to go down different paths. – DeveloperChris Jan 4 '16 at 21:51
0

The solution to my dilemma was simpler than I had imagined.

The problem of saving into symlinked folders is discussed here.. https://www.drupal.org/node/1008402 with a few patches to fix getlocalpath(). This was the basis for my temporary fix.

5 years and no patch has made it to production!

After posting here and struggling to get the solution working, which was being complicated by the module filefield_paths altering the workflow somewhat (files aren't save to the final location till later). I realised if I can create my own streamwrapper I can save the files where I like.

This turned out to be very easy and worked a treat.

I will post a link to the streamwrapper module when I have cleaned it up and submitted it to drupal.

I have created a sandbox project for this module here https://www.drupal.org/sandbox/developerchris/2644230

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.