Jump to content

Keep or store originale file name


suntrop
 Share

Recommended Posts

I need for an web app files that keep their original names. Like “A new flavour from Häagen-Dazs.pdf”. 

Why? Because my web app is some kind of file sharing (for a company) and those files need to be re-integrated into their original place. The company uses a DMS that partly relies on file names. If they get back “a-new-flavour-from-hagen-dazs.pdf” it’ll break consistency. 

  1. I tried but couldn’t get rid of the file name validation. Is it possible to disabled it?
  2. I couldn’t find a hook for file uploads. Is it possible to hook into it and change back the original name?
  3. ... or instead, save the original name in the file description? So when I download the file I can pass in the original name?
  4. Another ugly way would be to just store file paths in a multiplier or just a folder path (but that excludes admin users uploading files within PW)

I read a blog post by soma with an interesting solution to store files as a dedicated page. This would come in handy, because I need to manage access on all files anyway. Most files are coming from and front end upload form. But the admins will work on the PW backend and that is quite combersome to create for every file a new page, name it accordingly, upload the file and create a reference.

On github I found a workaround by @matjazp but the Dropbox link isn’t working anymore.

https://github.com/processwire/processwire-requests/issues/56#issuecomment-263669255

Link to comment
Share on other sites

Although it has worked for some, personally, I wouldn't bother with hooking into file uploads or storing original names in the file description or #4. I would either go for 'one-page-per-file' approach or create a custom Fieldtype that extends FieldtypeFile.

1. Page approach

Besides the advantages you've alluded to, other advantages are:

  1. You file 'gets a unique ID'. Normally, files/images do not have IDs. For a critical system like yours, you might find an ID useful, e.g. to easily locate files
  2. Extensible:  Using a page, you can add fields to it if such a requirement arises in the future. 
  3. Easy to edit files
  4. Edit a file in one place, have the changes applied everywhere you are using it
  5. Etc...

Now, this does look familiar... :). Media Manager uses the same approach. It is just a bit more refined. The pages containing media are hidden, are auto-created and users do no interact with them directly. Shameless plug; if all else fails; consider buying MM :P. I know one developer who used it to manage PDF files for an organisation.

2. Custom field

The task at hand is a good opportunity for a custom Fieldtype. Create a module that extends Fieldtypefile. Copy the code in Fieldtypefile, adjusting the schema to accept an additional text column/field (for the database) where you can save your original file name. We can help you with this

3. Profields Table?

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...