When using IMCE to attach a file to a field, you will get the following error if your field is setup to use private files:

"The selected file could not be used because the file does not exist in the database."

To me it seems like the $file_directory_prefix in filefield_source_imce_value() is incorrect when private files are being used.
When private files are being used, $file_directory_prefix is the path of your private files folder (in my case "sites/default/private"), while I think this should always be "system/files" for private files.

Otherwise the preg_replace will fail, which will result in a query that will always have an empty result, which will in turn result in the error.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Daluxz’s picture

Status: Active » Needs review
FileSize
680 bytes

Here's a patch.

Dubs’s picture

Thanks for taking to time to write and submit this module.

The patch works - can it please be submitted?

quicksketch’s picture

Status: Needs review » Needs work

Hi guys. Thanks for this patch. I think you're correct. This patch looks like it would fix some issues with private files, but it wouldn't fix the situation where private files are being used by Clean URLs are turned off. For now I've committed this patch anyway, since it solves most of the problem. I'm moving this to needs work for the second part of the problem.

zikaelismik’s picture

Is there any news about this? I've installed latest version but still i get the same message
"The selected file could not be used because the file does not exist in the database."
when trying to reference an existing file (uploaded as private).

hepabolu’s picture

I've modified the code in the patch to allow extra characters between the base path and the 'system/files'. For me, that was necessary because I have language codes in the URL after the base path. This is my first patch file, so please let me know if it's not ok.

  • quicksketch committed 40b7004 on 8.x-1.x
    Issue #1853946 by Daluxz: Error attaching private files via IMCE.
    
e5sego’s picture

I run into same problem as hepabolu with setup having language negotiation by path prefix enabled. His patch did not work for me, so I created another one.

e5sego’s picture

FileSize
778 bytes