What is the proper way to update files like pictures without loosing the reference to other doctypes?
You should be able to replace the file while maintaining the file name upon upload. This should maintain links, no?
Can you give an example using docTypes to describe it?
So in this case it’s not a doctype but really files in tools/file
looks like that for an example file:
unfortunately I can not find any options to replace, upade…
There are a few things to understand regarding how File (docType) works.
This is from my own testing and findings. I hope this is accurate for all cases.
When a file is uploaded (either directly in the File docType list) or by attaching a file via another docType) the system creates a record in tabFile
.
You can see the fields in your screenshot. Notice the field “Content Hash”. This is how Frappe tracks if a file is a duplicate or not.
If I try uploading a file that already exists (including the filename), the system will not overwrite the existing nor add a duplicate. The first file will be used.
If I upload a file with the same name but different content, the system will see a different “Content Hash”. Since this is a unique file with the same name, Frappe will upload the file but append the filename with a random string.
If I delete a file from the file list and this file is referenced in other docTypes, then the database entry (file record/docType) is deleted but the referenced file remains in the filesystem.
If I delete a file from the file list (that was uploaded by attaching to a docType), the reference will be removed from the docType and the database entry deleted. The actual file will remain in the filesystem at /private/files directory.
If I manually replace a file using ssh, the file links will work but the “Content Hash” doesn’t get updated. This means if I try to upload the same file, it will get an appended filename.
One really strange behavior is what happens to files that have the name appended by frappe. The original filename show in the “virtual file list” aka Library.
In summary, the File docType is not designed for updating files. You’ll need to know all of the planned behavior to make your changes to get your desired outcome.
I think if you’d like to update a file, your best bet is to use external means to change the file content. Don’t change the file name. This means you’ll need to be aware that the “Content Hash” will be incorrect once you update the file via ssh/scp/sftp/etc.
Thank you very much for this detailed explanation. I had the same feeling, that file names are only one side of the story, content hash is maybe even more important.
I’m still thinking how to manage my website assets in the most practical way…
For internal documents this behavior of frappe is totally fine. but for website assets having this behavior feels a bit restrictive and annoying.
I think it can be used efficiently.
With that said, all files go in a single directory. If there are thousands of files, this can cause slow access.
You will need to come up with your own rules and procedures. For example, you can make a practice of always using the URL to embed in web pages. This way you’ll just need to make sure the file exists in the public or private directory.