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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

foopang’s picture

Status: Active » Needs review
FileSize
692 bytes
travismark’s picture

Patch works for me :) Thanks...

Andre-B’s picture

Issue summary: View changes

if 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.

Andre-B’s picture

Status: Needs review » Needs work
stmh’s picture

Issue summary: View changes

The patch will fix the SQL-error, but does not update the file-content. Here's an easy example to reproduce it:

$result = file_save_data('initial file', 'storage-field-image-file://test.txt', FILE_EXISTS_REPLACE);
dsm($result);

$result = file_save_data('overwritten with data', 'storage-field-image-file://test.txt', FILE_EXISTS_REPLACE);
dsm($result);

(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.

DamienMcKenna’s picture

Issue summary: View changes
leewoodman’s picture

Any update on resolving the key issue?...seems like a pretty fundamental issue.

Perignon’s picture

No update. #5 raised an issue with the supplied patch.

mikkmiggur’s picture

Any 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.