media-command icon indicating copy to clipboard operation
media-command copied to clipboard

Cannot bulk import media

Open crtl opened this issue 6 years ago • 6 comments

Bug Report

I have around 2.6k images in a subdirectory inside wp-content/uploads/product_images. I tried to import them but get the following error:

$ wp media import ./product_images/*.png --skip-copy
/.../Composer/vendor/wp-cli/wp-cli/bin/wp: line 45: /c/xampp/php/php: Argument list too long
/.../Composer/vendor/wp-cli/wp-cli/bin/wp: line 45: /c/xampp/php/php: No error

The command evaluates the blob and just appends all files as arguments for the php command which seems to be too long for php to handle.

crtl avatar Aug 26 '19 12:08 crtl

@crtl The ./product_images/*.png bit in your command is already expanded by your shell in this case. The shell will expand this while examining the filesystem and then pass on a file list that matches this pattern to the actual tool being called, like so:

$ wp media import ./product_images/image1.png ./product_images/image2.png ./product_images/image3.png ... --skip-copy

So there's nothing that WP-CLI can do here, as the problem already occurs before you're even hitting the WP-CLI tool.

However, I notice now that the documentation says the command would support glob capabilities, which doesn't seem to be the case as far as I can see from the source code. If that would be the case, you could provide the "unglobbed" string to wp media import by quoting it, which I don't think works right now:

wp media import './products_images/*.png' --skip-copy

So a solution to this problem would be to add actual globbing support to the command and then handling the expansion within PHP memory.

schlessera avatar Sep 09 '19 06:09 schlessera

The solution would be to support passing directory names and a recursive option to the command.

crtl avatar Sep 09 '19 06:09 crtl

Directory names are not precise enough for this. Actual globbing would be preferable, and PHP already supports this out of the box, so it'd be easier to implement as well.

schlessera avatar Sep 09 '19 07:09 schlessera

How can you decide whats precise and what not. The command is pretty useless if you can only upload a limited amount of images because for small amounts you can just use the normal media upload in the admin dashboard.

crtl avatar Sep 09 '19 12:09 crtl

The goal is to make this more useful by allowing you to control what to include at the WP-CLI level, instead of relying on the shell.

But adding folders and a recursive option is both more complicated and less flexible than just passing the provided argument through the PHP glob() function.

schlessera avatar Sep 11 '19 09:09 schlessera

Was getting an error while attempting to bulk import. Warning: Unable to import file 'images/*.webp'. Reason: File doesn't exist.

Then I realized that I had the path in quotes. The docs show an example for bulk imports with an unquoted path. Removing the quotes fixed the issue.

It's not a huge deal, but I was expecting the string path to work too.

Any update on this?

bgoewert avatar Mar 17 '22 15:03 bgoewert