Score:0

How can I resolve the "Unique file URI" when using managed_file field in form API with a file name that already exists?

mv flag

I am facing a strange issue with a managed_file field in my Drupal form API. Whenever I upload a file and save the form, and then come back again to upload another file with the same name, I get this error message.

The specified file xyz.png could not be uploaded. The file temporary://xyz.png already exists. Enter a unique file URI.

However, if I try to upload the file again, it gets uploaded successfully with the file name renamed.

I noticed a similar issue reported in the module issue queue.

Can anyone suggest why this might be happening and how to fix it?

id flag
I think you indicated that you have a custom code implementation. If you do we need to see that in order to answer your question.
Zuhair avatar
mv flag
Added my code here - https://github.com/zuhairkareem/form_api-test/ , this is multistep form, step 1 there is managed_file, file stored in temporary folder, Step2 - get name & emal, on Submit- move file from temporary folder to Public folder, I think the issue is due to moving from temporary folder to public folder in step 2.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.