Closed (fixed)
Project:
File Entity (fieldable files)
Version:
7.x-2.x-dev
Component:
Code
Priority:
Major
Category:
Feature request
Assigned:
Issue tags:
Reporter:
Created:
20 May 2014 at 18:16 UTC
Updated:
5 Jun 2017 at 11:25 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
recrit commentedThe attached patch adds the following:
* Allows all mimetype extensions based on the file type settings.
* If the file name changes, then the file entity uri is updated and the original file in the file system is deleted (ie no the file entity).
Comment #3
recrit commentedupdate patch to copy and rename if new file has a different name than the original. This will help avoid collisions with other existing files.
Comment #4
recrit commentedComment #5
recrit commentedadding interdiff
Comment #6
recrit commentedrolled against the latest 7.x-2.x 5e9c095
Comment #7
mglamanAwesome, this will make some clients happy. Especially useful if you uploaded a video as JPEG and then realized "oh no, that should be transparent PNG" or something crazy like that.
Comment #8
fabianx commentedNice!
RTBC + 1
nit - typo
Comment #9
catchAlso agreed on RTBC - I've tested this manually and via automated behat tests for a client.
Comment #10
recrit commentedfixed misspelling
Comment #11
stuchl4n3k commentedWould somebody please explain, why it was designed to maintained extensions in the first place?
Comment #12
fabianx commentedBecause it was designed to keep the same filename, so when you had originally uploaded a JPG file called test.jpg and then uploaded a GIF, you would end up with test.jpg with GIF content :-D, which is quite bad.
The reason was / is that images can be e.g. inserted into text areas and the links to them are persistent.
Comment #14
aaron commentedCommitted to http://drupalcode.org/project/file_entity.git/commit/9a13484.
Comment #15
dave reidRe-opening this for some follow-ups and missing test coverage for the new API function as well as replacement functionality.
Should this logic actually be in file_entity_file_update() checking to see if $file->original->uri != $file->uri?
A message isn't really desired here, we should remove this.
Comment #16
bneil commentedComment #17
dave reidComment #18
haleagar commentedJust a note: this causes a drastic change in behaviour compared in file_entity 7.x-2.0-beta1 and file_entity 7.x-2.0-beta2 vs file_entity 7.x-2.0-alpha.
In file_entity 7.x-2.0-alpha and previous versions if you use the file replace option the original file name (in the file system) was retained and all hard links to that file remain valid.
After this change the file name (in the file system) is changed and any links to the file such as use in a wysiwyg field are broken.
I realize that either behaviour could be argued as correct, but in my opinion the previous behaviour is a more desirable and expected behaviour than the new.
I would say it is *much less* often needed to upload a new image file that has a different extension, than it is to replace a file with one of the same type.
I would suggest that it would be desirable to modify this function such that the file name is only changed when needed by a change in the file extension, or possibly only when expressly requested by the user by a option on the edit form.
Comment #19
haleagar commentedHere is a simple patch on current Oct 3 2015 dev (7.x-2.0-beta2+13-dev) that does what I suggested above to maintain the file name if the new file is of the same type.
Comment #20
gmclelland commentedPatch attached. NR
Comment #21
chaseonthewebI've opened #2820380: File replace no longer preserves original filename to address the issue @haleagar brought up.
Setting this issue back to NW for Dave's comments in #15.
Comment #22
joseph.olstadComment #24
joseph.olstadsee related issue
making this change, 2 years long enough without any objections.
#2820380: File replace no longer preserves original filename