Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Sometimes we need to upload a file to replace an existing file instead of adding it as a new file in the file system. For example, you can upload a same file using file_save_data() with the FILE_EXISTS_REPLACE flag. Storage API will try to create a new entry in the 'storage_core_bridge' table no matter the uri is existing or not. It will cause the duplicate entry for key 'uri' error if the uri has already existed. The patch below checks for the uri existence before trying a create new entry in the 'storage_core_bridge' table.
Comment | File | Size | Author |
---|---|---|---|
#1 | storage_api_duplicate_key_uri-2068579.patch | 692 bytes | foopang |
Comments
Comment #1
foopang CreditAttribution: foopang commentedComment #2
travismark CreditAttribution: travismark commentedPatch works for me :) Thanks...
Comment #3
Andre-Bif you replace the file, shouldnt it be marked for removal/ removed from the storage_core_bridge and all of the containers? For a new file the workflow should contain uploading to containers as well.
Comment #4
Andre-BComment #5
stmh CreditAttribution: stmh commentedThe patch will fix the SQL-error, but does not update the file-content. Here's an easy example to reproduce it:
(Adjust the uri accordingly) Look into the file, it's content is still "initial content".
As my experience with storage_api is limited I am happy for any pointers where to look, as this is a showstopper for our current project.
Comment #6
DamienMcKennaComment #7
leewoodman CreditAttribution: leewoodman commentedAny update on resolving the key issue?...seems like a pretty fundamental issue.
Comment #8
Perignon CreditAttribution: Perignon commentedNo update. #5 raised an issue with the supplied patch.
Comment #9
mikkmiggur CreditAttribution: mikkmiggur commentedAny solution for that issue?
In my case "Replace file" will be uploaded as a separate file and then I got that Duplicate entry error.
And in that error is used the file name of the old file.