humanmade / S3-Uploads

The WordPress Plugin to Store Uploads on Amazon S3
1.95k stars 392 forks source link

Uploads fails using S3_UPLOADS_USE_LOCAL #586

Open garubi opened 2 years ago

garubi commented 2 years ago

S3-Uploads ver 3.0.4 installed using manual-install.zip

I'm in local development (using Local by Flywheel 6.4.1, Ngnix, Php 8.0.0 on Windows )

I added in wp-config.php the row define( 'S3_UPLOADS_USE_LOCAL', "true" );

The uploads fail with the error: Unable to create directory uploads/2022/07. Is its parent directory writable by the server?

I verified to have allow_url_fopen = On

Being on Windows it's unlikely that's really a permission issue... Maybe the local wrapper fails?

Tryed also with WP-CLI wp s3-uploads verify

but failed with a fatal error:


#0 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\plugins\S3-uploader-manual-install\inc\class-local-stream-wrapper.php(177): fopen('', 'wb')
#1 [internal function]: S3_Uploads\Local_Stream_Wrapper->stream_open('s3://pandora-de...', 'wb', 0, NULL)
#2 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\plugins\S3-uploader-manual-install\inc\class-wp-cli-command.php(34): copy('C:\\Users\\Stefan...', 's3://pandora-de...')
#3 [internal function]: S3_Uploads\WP_CLI_Command->verify_api_keys(Array, Array)
#4 phar://C:/Users/Stefano Garuti/AppData/Local/Programs/Local/resources/extraResources/bin/wp-cli/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(100): call_user_func(Array, Array, Array)
#5 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
#6 phar://C:/Users/Stefano Garuti/AppData/Local/Programs/Local/resources/extraResources/bin/wp-cli/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(491): call_user_func(Object(Closure), Array, Array)
#7 phar://C:/Users/Stefano Garuti/AppData/Local/Programs/Local/resources/extraResources/bin/wp-cli/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(417): WP_CLI\Dispatcher\Subcommand->invoke(Array, Array, Array)
#8 phar://C:/Users/Stefano Garuti/AppData/Local/Programs/Local/resources/extraResources/bin/wp-cli/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(440): WP_CLI\Runner->run_command(Array, Array)
#9 phar://C:/Users/Stefano Garuti/AppData/Local/Programs/Local/resources/extraResources/bin/wp-cli/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1237): WP_CLI\Runner->run_command_and_exit()
#10 phar://C:/Users/Stefano Garuti/AppData/Local/Programs/Local/resources/extraResources/bin/wp-cli/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#11 phar://C:/Users/Stefano Garuti/AppData/Local/Programs/Local/resources/extraResources/bin/wp-cli/wp-cli.phar/vendor/wp-cli/wp-cli/php/bootstrap.php(78): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#12 phar://C:/Users/Stefano Garuti/AppData/Local/Programs/Local/resources/extraResources/bin/wp-cli/wp-cli.phar/vendor/wp-cli/wp-cli/php/wp-cli.php(27): WP_CLI\bootstrap()
#13 phar://C:/Users/Stefano Garuti/AppData/Local/Programs/Local/resources/extraResources/bin/wp-cli/wp-cli.phar/php/boot-phar.php(11): include('phar://C:/Users...')
#14 C:\Users\Stefano Garuti\AppData\Local\Programs\Local\resources\extraResources\bin\wp-cli\wp-cli.phar(4): include('phar://C:/Users...')
#15 {main}
  thrown in C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\plugins\S3-uploader-manual-install\inc\class-local-stream-wrapper.php on line 177```
rmccue commented 2 years ago

Note that your configuration should be

define( 'S3_UPLOADS_USE_LOCAL', true );

(No quotes around the true value.)

fopen('', 'wb') seems suspicious, and would indicate you're hitting this conditional:

https://github.com/humanmade/S3-Uploads/blob/cafb1d4436c65f12c722ff0e8a900ca8b1bbd683/inc/class-local-stream-wrapper.php#L148-L152

That is, I suspect realpath() is returning false as your upload directory potentially doesn't exist or can't be created.

My guess would be that this is a permissions issue with PHP not being able to write to either the uploads directory, or create the subdirectory within it.

garubi commented 2 years ago

@rmccue thanks for your reply.

I corrected this: define( 'S3_UPLOADS_USE_LOCAL', true ); don't know why I put it in quotes, but this doesn't changed the problem.

I performed some more checks and I discovered that the wrapper can successfully create the uploads folders and subfolders, but it can't upload/write the files: the folders are empty.

About your suggestion that realpath() fails I think I can confirm it: in debug.log I have:

[18-Jul-2022 08:29:07 UTC] PHP Fatal error:  Uncaught ValueError: Path cannot be empty in C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\plugins\S3-uploader-manual-install\inc\class-local-stream-wrapper.php:177
Stack trace:
#0 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\plugins\S3-uploader-manual-install\inc\class-local-stream-wrapper.php(177): fopen('', 'wb')
#1 [internal function]: S3_Uploads\Local_Stream_Wrapper->stream_open('s3://pandora-de...', 'wb', 0, NULL)
#2 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-admin\includes\file.php(983): move_uploaded_file('C:\\Users\\Stefan...', 's3://pandora-de...')
#3 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-admin\includes\file.php(1074): _wp_handle_upload(Array, Array, NULL, 'wp_handle_uploa...')
#4 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-includes\rest-api\endpoints\class-wp-rest-attachments-controller.php(1228): wp_handle_upload(Array, Array)
#5 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-includes\rest-api\endpoints\class-wp-rest-attachments-controller.php(240): WP_REST_Attachments_Controller->upload_from_file(Array, Array)
#6 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-includes\rest-api\endpoints\class-wp-rest-attachments-controller.php(158): WP_REST_Attachments_Controller->insert_attachment(Object(WP_REST_Request))
#7 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-includes\rest-api\class-wp-rest-server.php(1143): WP_REST_Attachments_Controller->create_item(Object(WP_REST_Request))
#8 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-includes\rest-api\class-wp-rest-server.php(990): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/wp/v2/media', Array, NULL)
#9 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-includes\rest-api\class-wp-rest-server.php(414): WP_REST_Server->dispatch(Object(WP_REST_Request))
#10 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-includes\rest-api.php(394): WP_REST_Server->serve_request('/wp/v2/media')
#11 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-includes\class-wp-hook.php(307): rest_api_loaded(Object(WP))
#12 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-includes\class-wp-hook.php(331): WP_Hook->apply_filters('', Array)
#13 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-includes\plugin.php(524): WP_Hook->do_action(Array)
#14 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-includes\class-wp.php(398): do_action_ref_array('parse_request', Array)
#15 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-includes\class-wp.php(770): WP->parse_request('')
#16 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-includes\functions.php(1330): WP->main('')
#17 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-blog-header.php(16): wp()
#18 C:\Users\Stefano Garuti\Local Sites\bcok\app\public\index.php(17): require('C:\\Users\\Stefan...')
#19 {main}
  thrown in C:\Users\Stefano Garuti\Local Sites\bcok\app\public\wp-content\plugins\S3-uploader-manual-install\inc\class-local-stream-wrapper.php on line 177