I have isolated this issue. Here is the setup:

Vanilla Drupal Version 7.38
Media Version: 7.x-2.0-beta1+1-dev
Media Bulk Upload Version: 7.x-2.0-beta1+1-dev

/admin/config/media/file-system is Default download method: Amazon Simple Storage Service

When I don't set a File directory location, the images upload with no errors. The s3 bucket is configured correctly and we upload multiple other field images using filefield sources, core image upload widget, etc.

Here is the problem:

When setting the File directory as a subfolder for a field using the "media browser" plugin, the upload fails with this following error in the log:

Location:
http://www.example.com/media/browser?render=media-popup&types%5Bimage%5D...

Referrer:
http://www.example.com/media/browser?render=media-popup&types%5Bimage%5D...

Message:
File temporary://p19sdd1jmn19gkepd1q876q91rrp4.tmp could not be copied, because the destination directory s3://content_images is not configured correctly.

CommentFileSizeAuthor
#16 rtrim-path-in-mkdir-2549161-15.patch665 bytesloze

Comments

Steven T Habel created an issue. See original summary.

Anonymous’s picture

Thank you for the detailed writeup! I'll get to work debugging this as soon as I can.

Anonymous’s picture

I think I'm missing something. I don't know what this "media browser" plugin you're talking about is. It doesn't appear to be a part of Media or Bulk Media Upload, at least not that Ic an find. Maybe I'm just failing to find it. What steps do I have to do to access this media browser?

Anonymous’s picture

OK, upon further testing, I think you were talking about the "Media browser" widget for File fields. That makes sense. Unfortunately, I haven't been able to trigger this error on my Drupal testing instance. And I'm also not sure what Media Bulk Upload has to do with anything.

Could you please describe an exact set of steps for setting up a broken configuration, and then triggering the error?

cthshabel’s picture

Okay, thank you so much for looking this over.

It is the "Media Browser" widget for the file field. I have S3 as the main Upload destination for the entire drupal file system. It is also set as the "Upload Destination: S3 File System" on the specific field that's having the error. So when the file field is set as media browser widget on the form, I upload the image file, but it fails with the errors ONLY when a subfolder is set in the "File directory" in the "Edit" tab for the field. It works when there is no subfolder "File directory" value set.

The problem is all the images are loaded to the root of the S3 bucket, and we need the images for this field loaded to a subfolder. It does work loading to subfolder with the core "image widget", and other file field widgets, just not with media browser widget (when subfolder is set).

Thanks again. Please let me know what else i can do to help.

Anonymous’s picture

That's so weird, because I have no problems at all when using a "File directory" in my field settings. That might be some kind of interaction with one of the other modules I have installed in my test instance, though. I'll try disabling everything I'm not using.

cthshabel’s picture

Oh I think I found something else important! There is a patch applied to the media module. The media browser allows multiple select via plupload integration. It works great too btw. We have been using it (up to this point) with no problems.

Here is the patch and EXACT configuration that's currently being used and works great, except when the "File directory" is set it has errors:

https://www.drupal.org/node/951004#comment-10073966

Now that I look closer, I'm wondering if the patch in comment #136, which was used (https://www.drupal.org/node/951004#comment-9681531) is causing this is with the subfolder in S3?

cthshabel’s picture

Okay, I can confirm it is somehow related to the small media patch I added:

https://www.drupal.org/files/issues/allow_selecting_of-951004-136.patch

After reverting, the subfolder file directory works fine.

I'm not sure anyone in that issue queue would understand S3 file system or how to fix, but maybe I should post there?

Do you think it is somehow related to the function media_field_widget_process_multiple in media.fields.inc, since it adds a new _POST method?

I am actively looking at this to allow multiple items to post and upload to S3, very cool if we can get it working.

Thanks again

cthshabel’s picture

Okay, another interesting update.

After testing reverting to the original media module WITHOUT the patch, it worked. The subfolder directory was created on the S3 bucket.

Then, something interesting happened. I added the patch again, flushed the caches, and it still works. It seems like Drupal didn't have access yet (somehow mkdir) wasn't happening when the patch was applied and the subfolder file directory wasn't stored yet?

Either way, we can close this I think now. But it would be nice to know WHY this was happening. It may become an issue if that patch from the media module issue is ever added to an official release.

Thanks so much for all your help

Anonymous’s picture

I have no idea what code in that patch could possibly be causing subfolders to fail. All I can think of is maybe changing the field to unlimited cardinality, and storing multiple files in there, might be triggering an entirely different codepath that actually has the bug in it.

I'll try applying this patch to see if I can duplicate the problem. Once I have a running bug, I can debug into it to try to find the culprit.

Anonymous’s picture

Are there any other patches you've got applied to the base copy of 7.x-2.0-beta1+1-dev, besides this one?

cthshabel’s picture

@coredumperror I'm sorry I didn't ever see you responded!

I came back to this issue today to figure out what was the problem again. I was having another directory failure.

Your comment about the unlimited cardinality was the issue. When I reduced it to one (1 single image), then upload a single image, then switch it back to unlimited, it loads multiple fine.

So I think the patch is irrelevant here? It was the only patch I loaded into media module.

Should we close this issue? Or is there a way to allow "unlimited" cardiality to work with the module? Either way we found a nice, very simple, workaround.

Thanks!

Anonymous’s picture

That behavior you just described makes me think that the codepath in Media for multi-image upload doesn't properly create the subfolder before trying to put the files into it. Although, that should fail to everyone, rather than just users of s3fs, so maybe it's something else.

I'll look into this tomorrow, now that I know the multi-image upload functionality is the key.

Anonymous’s picture

Status: Needs work » Closed (cannot reproduce)

I'm closing this issue for cleanup purposes. If you're still having trouble with this, feel free to re-open it.

loze’s picture

I'm getting this error. I got it once before and forgot what I did to fix it.

The issue for me is, my upload path uses date tokens. If im using the multi uploader and the folder does not exist on s3 then I get the error.

When I use a single file uploader, the folder is created and it works as expected. Subsequent uploads using the multi uploader then work because the folder does exist.

I do not have this issue with local file storage only with s3://

Since im using date tokens, this happens every morning when the day changes unless someone uploads something using the single file uploader and creates the folder.

I'm not sure if this is an issue with s3fs or the media module. But as I said I have come across this before and hacked my own patch to one of them to get it working. Been digging through my commits to figure out what it was but I cant seem to find it. Ill report back if I do. But if someone has a suggestion, I'm all ears. Cus I'm stumped ATM.

thanks.

loze’s picture

StatusFileSize
new665 bytes

I think i've gotten to the bottom of this!
Apparently, the dir path was being stored in s3fs_file with a trailing slash. I had 's3://media/2016/06/16/' when it should of been 's3://media/2016/06/16'

It appears that the latest dev tries to fix this (maybe?) by doing $folders[rtrim($folder_uri, '/')] = TRUE; around line 380
not sure if the point of that change was to fix this issue. Nevertheless, it persists for me in the latest dev.

So I added a rtrim($dir, '/'); to the mkdir function in the stream wrapper, and it seems to have cleared this up for me now.

patch is attached.

loze’s picture

Status: Closed (cannot reproduce) » Needs review

  • coredumperror committed 94c3a04 on 7.x-2.x authored by loze
    Issue #2549161: S3fsStreamWrapper.mkdir() now trims trailing slashes.
    
Anonymous’s picture

That change you noticed is, in fact, related to the issue of trailing slashes in folder names. Though obviously it wasn't a sufficient change to fix the problem. In fact, I'm pretty surprised that no one else ran into the problem that you patch fixes until now. I wonder why?

Anyway, this patch is great, so I'll commit it momentarily.

  • coredumperror committed 94c3a04 on 7.x-3.x authored by loze
    Issue #2549161: S3fsStreamWrapper.mkdir() now trims trailing slashes.
    
sgdev’s picture

Status: Needs review » Fixed

This has been committed for both versions, I'm assuming it can be closed?

Status: Fixed » Closed (fixed)

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