0

i have some file upload fields which works great. the file is stored on public file system and will be able to get downloaded from the users (in a specific node).

the issue is when i update the file (pdf) with a new version in the same month, drupal renames the file and save a new instance instead of updating the file (i know the reasons, avoiding global file conflicts on the page).

the user will download the renamed file which is wrong (e.g. manual_1.pdf). how can i change the filename into the name that is in its metadata (manual.pdf).

is there any hook, module or settings?

2

Is all depends on how your loading the file information. As the filename field in the file_managed table will always be whatever is uploaded. e.g. filename = mypdf.pdf uri = mypdf_1.pdf

So you can always use the filename value for the real file name. It sounds like whatever you're using to load the file/create the file link isn't using this correct value

|improve this answer|||||
  • yep you are right. ive already seen the file_managed table. the real name is always the same. however thank you! – Gabbax0r Jan 16 '18 at 15:11
1

the file is stored on public file system

The problem with using the public file system is that the file is actually served by your web server, not Drupal.

So if you want to manipulate it in any way, you'll have to switch to private. This does add more overhead. Test your configuration with big file sizes to see if they're handled okay.

Your other option is changing the path where the files are stored. You can use a token that includes the date (maybe time? depends how frequently they might be updated) of when the file was uploaded. Most files will end up in different folders and that will solve your issue since files are only renamed if there's a collision in the folder it's writing to.

 

For a live site with files, there are 3 options I can think of.

Option 1: if there’s a pattern to the files, you could modify the .htaccess so those are rewritten to the index.php.

Option 2: You can change the public file path to something else. You can then change the private file path to the previous public one. This would mean all current files would now be served as private. You would need to adjust the fields you want so they now write to private.

Option 3: Modify the path of the files you want on the database so they are served from the private path. Then move those files from the public file path to the private file path.

|improve this answer|||||
  • the main problem is, that the building process of the page is already finished and live, filesystem > 10000 files and no way to reupload them for private file system – Gabbax0r Jan 17 '18 at 9:26
  • 1
    @Gabbax0r I edited my answer adding the options I can think of if you have a site with files. Hoping it helps! – rovr138 Jan 17 '18 at 11:06
  • 1
    i found a solution myself because serving from the private file system doesnt make any diffrence for the existing files. so i build a custom module and changed the 'download link' to my own routing and return the file with my own response-headers. thank you! – Gabbax0r Jan 17 '18 at 12:22

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.