humanmade / S3-Uploads

The WordPress Plugin to Store Uploads on Amazon S3
1.92k stars 389 forks source link

Uploads fail using S3_UPLOADS_USE_LOCAL #630

Open henriquevcosta opened 1 year ago

henriquevcosta commented 1 year ago

I just added this plugin in a Bedrock multisite environment running on Lando and because I'm in a local dev environment I'm using S3_UPLOADS_USE_LOCAL=true but am having an error that I really can't understand.

I appreciate that my webroot isn't really standard (/app/src/bedrock/web) but everything else seems to be working. At first glance I thought it could be permissions, but actually the plugin is able to create the folder structure and in a shell inside the container I can create files with that user.


[Sun Apr 30 06:40:32.910833 2023] [php:warn] [pid 1155] [client 172.21.0.2:53062] PHP Warning:  opendir(/app/src/bedrock/web/app/uploads/sites/2/s3/fake-bucket/uploads/sites/2/2023/04/lanoxin*): Failed to open directory: No such file or directory in /app/src/bedrock/web/app/mu-plugins/s3-uploads/inc/class-local-stream-wrapper.php on line 515, referer: https://cenas.mywebsite.lndo.site/wp/wp-admin/post.php?post=3&action=edit
[Sun Apr 30 06:40:32.910932 2023] [php:warn] [pid 1155] [client 172.21.0.2:53062] PHP Warning:  scandir(s3://fake-bucket/uploads/sites/2/2023/04/lanoxin*): Failed to open directory: "S3_Uploads\\Local_Stream_Wrapper::dir_opendir" call failed in /app/src/bedrock/web/app/mu-plugins/s3-uploads/inc/class-plugin.php on line 668, referer: https://cenas.mywebsite.lndo.site/wp/wp-admin/post.php?post=3&action=edit
[Sun Apr 30 06:40:32.910951 2023] [php:warn] [pid 1155] [client 172.21.0.2:53062] PHP Warning:  scandir(): (errno 2): No such file or directory in /app/src/bedrock/web/app/mu-plugins/s3-uploads/inc/class-plugin.php on line 668, referer: https://cenas.mywebsite.lndo.site/wp/wp-admin/post.php?post=3&action=edit
[Sun Apr 30 06:40:32.911187 2023] [php:error] [pid 1155] [client 172.21.0.2:53062] PHP Fatal error:  Uncaught TypeError: S3_Uploads\\Plugin::get_files_for_unique_filename_file_list(): Return value must be of type array, bool returned in /app/src/bedrock/web/app/mu-plugins/s3-uploads/inc/class-plugin.php:668\nStack trace:\n#0 /app/src/bedrock/web/wp/wp-includes/class-wp-hook.php(308): S3_Uploads\\Plugin->get_files_for_unique_filename_file_list(NULL, 's3://fake-bucke...', 'lanoxin.png')\n#1 /app/src/bedrock/web/wp/wp-includes/plugin.php(205): WP_Hook->apply_filters(NULL, Array)\n#2 /app/src/bedrock/web/wp/wp-includes/functions.php(2643): apply_filters('pre_wp_unique_f...', NULL, 's3://fake-bucke...', 'lanoxin.png')\n#3 /app/src/bedrock/web/wp/wp-admin/includes/file.php(961): wp_unique_filename('s3://fake-bucke...', 'lanoxin.png', NULL)\n#4 /app/src/bedrock/web/wp/wp-admin/includes/file.php(1082): _wp_handle_upload(Array, Array, NULL, 'wp_handle_uploa...')\n#5 /app/src/bedrock/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php(1228): wp_handle_upload(Array, Array)\n#6 /app/src/bedrock/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php(240): WP_REST_Attachments_Controller->upload_from_file(Array, Array)\n#7 /app/src/bedrock/web/wp/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php(158): WP_REST_Attachments_Controller->insert_attachment(Object(WP_REST_Request))\n#8 /app/src/bedrock/web/wp/wp-includes/rest-api/class-wp-rest-server.php(1181): WP_REST_Attachments_Controller->create_item(Object(WP_REST_Request))\n#9 /app/src/bedrock/web/wp/wp-includes/rest-api/class-wp-rest-server.php(1028): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/wp/v2/media', Array, NULL)\n#10 /app/src/bedrock/web/wp/wp-includes/rest-api/class-wp-rest-server.php(442): WP_REST_Server->dispatch(Object(WP_REST_Request))\n#11 /app/src/bedrock/web/wp/wp-includes/rest-api.php(410): WP_REST_Server->serve_request('/wp/v2/media')\n#12 /app/src/bedrock/web/wp/wp-includes/class-wp-hook.php(308): rest_api_loaded(Object(WP))\n#13 /app/src/bedrock/web/wp/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array)\n#14 /app/src/bedrock/web/wp/wp-includes/plugin.php(565): WP_Hook->do_action(Array)\n#15 /app/src/bedrock/web/wp/wp-includes/class-wp.php(399): do_action_ref_array('parse_request', Array)\n#16 /app/src/bedrock/web/wp/wp-includes/class-wp.php(780): WP->parse_request('')\n#17 /app/src/bedrock/web/wp/wp-includes/functions.php(1334): WP->main('')\n#18 /app/src/bedrock/web/wp/wp-blog-header.php(16): wp()\n#19 /app/src/bedrock/web/index.php(6): require('/app/src/bedroc...')\n#20 {main}\n  thrown in /app/src/bedrock/web/app/mu-plugins/s3-uploads/inc/class-plugin.php on line 668, referer: https://cenas.mywebsite.lndo.site/wp/wp-admin/post.php?post=3&action=edit
172.21.0.2 - - [30/Apr/2023:06:40:32 +0000] "POST /wp-json/wp/v2/media?_locale=user HTTP/1.1" 500 638 "https://cenas.mywebsite.lndo.site/wp/wp-admin/post.php?post=3&action=edit" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.2 Safari/605.1.15"

Do you have any idea what could be causing this? Is it a bad configuration that I set, or is it really a bug? Please let me know if you need any more info

Context:

rasmuswinter commented 1 year ago

This issue has been addressed on the master branch, but the commits have not been applied to the v3-branch yet (which is where releases are created)

This PR, which applies 3 commits from master, should resolve this

LarkRiseMedia commented 8 months ago

So I am running 3.0.7 and the error I previously had when running locally

"The server cannot process the image. This can happen if the server is busy or does not have enough resources to complete the task. Uploading a smaller image may help. Suggested maximum size is 2,560 pixels."

not fixed on this issue?

all folders are created properly but file not uploaded.

Running PHP 8.1 on Herd Laravel.