When the file directory property of a file field is configured or renamed and it is not empty, the Field API in Drupal 7.23 does not create the directory. This is probably because the field supports tokens and it can not know all the possible replacements that are going to be available at that moment.

The end result is that the line below, taken from file_entity_add_upload_multiple_submit, fails to move the file in a non-existent directory, resulting in a failed file upload.
$destination = file_unmanaged_move($source, $destination, FILE_EXISTS_RENAME);

The log entry below is present in dblog:
File temporary://p188kgbfsjvuqh36pes11rl134q4.tmp could not be copied, because the destination directory public://uploaded-images-1 is not configured correctly.

Possible solution:
Add a defensive folder creation before starting the files move process.

Comments

ndobromirov’s picture

ndobromirov’s picture

Status: Active » Needs review

Change issue status to needs review.

ndobromirov’s picture

The patch in comment #1 applies with white-space warnings. Uploading new patch.

gmclelland’s picture

I wonder if the reason stated in this issue is what causes the problem here #1946298: upload_location directory not being created if it doesn't exist?

ndobromirov’s picture

I am using the plupload, so the patch that you linked probably will solve my issue also.
The thing, is that tomorrow(or some more days in the future) there is going to be another upload library integration that will use the file_entity_add_upload_multiple_submit method and it will have the issue again.

As it can be seen, they are fixing the problem (probabpy - not tested) for plupload module, but it is not fixed generally for all file_entity dependant modules.

I am open for discussion.

Update:
Just looked through the comments in the issue you posted and this is the exact same issue (no directory is created when uploading multiple files).

BR,
Nikolay Dobromirov.

gmclelland’s picture

@ndobromirov - Finally tested your patch in #3, but it didn't seem to work for me. I tested the patch by creating an unlimited multivalued image field that uses the media browser, plupload with the https://drupal.org/sandbox/fangel/1652676.

Strangely, the patch from #1946298-1: upload_location directory not being created if it doesn't exist which is very similar, is the only way I can get everything to work/function correctly.

Without the patch specifying a file upload directory for the image field, the directory doesn't get created. With the patch from #1946298-1: upload_location directory not being created if it doesn't exist it does.

The maintainer for plupload say's it not the plupload module's fault. I think your probably right that it should go into file entity, I'm just not sure why it's not working?

gmclelland’s picture

ndobromirov’s picture

I think that for some reason, you are not entering in the file_entity_add_upload_multiple_submit handler.
So you need to find the real submit handler that is used to upload the images in your case.

Suggesting a step by step execution with xdebug and some IDE (ex. Eclipse, NetBeans, etc.) to find the exact place in file_entity (or other module) that is responsible for performing the upload.

Some more info regarding my setup.
I hope it will point you in the right direction for solving your problem or at least find the differences.

projects[media_multiselect][type] = "module"
projects[media_multiselect][subdir] = "contrib"
projects[media_multiselect][download][type] = "git"
projects[media_multiselect][download][url] = "http://git.drupal.org/sandbox/fangel/1652676.git"
projects[media_multiselect][download][branch] = "7.x-1.x"
projects[media_multiselect][download][revision] = "1b4fc64bd6665aae92d58d65ea24c32557767738"
projects[media_multiselect][patch][] = "http://drupal.org/files/issues/media-multiselect_remove-button_removes_a..."
projects[media_multiselect][patch][] = "http://drupal.org/files/issues/required_validation-media_multiselect-213..."

projects[media][type] = "module"
projects[media][subdir] = "contrib"
projects[media][download][type] = "git"
projects[media][download][url] = "http://git.drupal.org/project/media.git"
projects[media][download][branch] = "7.x-2.x"
projects[media][download][revision] = "814c34ed30c81f6c279d2ef24b9079ee9be0b1ed"
projects[media][patch][] = "http://drupal.org/files/media-browser-view-library-exposed-form-submit-p..."
projects[media][patch][] = "http://drupal.org/files/media-notice-undefined-index-in-media_pre_render..."

libraries[plupload][download][type] = "file"
libraries[plupload][download][url] = "http://plupload.com/downloads/plupload_1_5_7.zip"
libraries[plupload][directory_name] = "plupload"
libraries[plupload][destination] = "libraries"
libraries[plupload][patch][] = "http://drupal.org/files/plupload-1_5_7-rm_examples-1903850-9.patch"

projects[plupload][subdir] = "contrib"
projects[plupload][version] = "1.4"

projects[file_entity][type] = "module"
projects[file_entity][subdir] = "contrib"
projects[file_entity][download][type] = "git"
projects[file_entity][download][url] = "http://git.drupal.org/project/file_entity.git"
projects[file_entity][download][branch] = "7.x-2.x"
projects[file_entity][download][revision] = "e80b22310889593ab8018c5c86649a60384ca854"
projects[file_entity][patch][] = "http://drupal.org/files/file_entity-revert-the-file-types-configurations..."
projects[file_entity][patch][] = "http://drupal.org/files/issues/file_entity-multiple-upload-does-not-resp..."
projects[file_entity][patch][] = "http://drupal.org/files/issues/file_entity-filter_out_missing_files.patch"

gmclelland’s picture

Status: Needs review » Reviewed & tested by the community

@ndobromirov - Thanks for that information.

I'm not sure why but now your patch is working. Maybe I didn't originally clear my caches good enough.

sheldonkreger’s picture

#3 also working for me.

gmclelland’s picture

I just updated my site to latest Media and File Entity 2.x-dev and the problem still exist.

The patch in #3 still applies and still fixes the problem.

Hope that helps

johnle’s picture

Patch #3 works for me to without any problem.

aaron’s picture

aaron’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

kenorb’s picture

Assigned: ndobromirov » Unassigned