You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to download an image that has escaped spaces in the URL an Exception is thrown:
Error: Exception: File could not be downloaded (https://www.domain.com/inc/upload/jobs/1428/mobile/detail_jobs1428_Banner op hotel site-3.jpg) 400 Bad Request: 2: file_get_contents(https://www.domain.com/inc/upload/jobs/1428/mobile/detail_jobs1428_Banner op hotel site-3.jpg): failed to open stream: HTTP request failed! HTTP/1.1 400 BAD_REQUEST , Bad Request (tried: fopen) (in /public_html/wire/core/WireHttp.php line 703)
WireHttp uses Sanitizer::url and encoded characters in the URL are replaced here. PHP's file_get_contents() needs spaces in a supplied URL to be encoded.
@ryancramerdesign, maybe Sanitizer::url could have a new option that allows encoded characters, and WireHttp could then use that option?
…() method was not working with URLs having encoded spaces when downloading with the "fopen" option (the "curl" option was not affected). Added a couple new $options to $sanitizer->url() method for dictating how encoded characters should be handled. Added WireHttp::setValidateURLOptions() method for cases where you want to manually specify different options for validating the URL in WireHttp.
Short description of the issue
When trying to download an image that has escaped spaces in the URL an Exception is thrown:
Error: Exception: File could not be downloaded (https://www.domain.com/inc/upload/jobs/1428/mobile/detail_jobs1428_Banner op hotel site-3.jpg) 400 Bad Request: 2: file_get_contents(https://www.domain.com/inc/upload/jobs/1428/mobile/detail_jobs1428_Banner op hotel site-3.jpg): failed to open stream: HTTP request failed! HTTP/1.1 400 BAD_REQUEST , Bad Request (tried: fopen) (in /public_html/wire/core/WireHttp.php line 703)
The URL for the image actually has been escaped, the URL of the image is:
https://www.domain.com/inc/upload/jobs/1428/mobile/detail_jobs1428_Banner%20op%20hotel%20site-3.jpg
Expected behavior
Image should be downloaded and added to the page.
Actual behavior
Error: Exception: File could not be downloaded (https://www.domain.com/inc/upload/jobs/1428/mobile/detail_jobs1428_Banner op hotel site-3.jpg) 400 Bad Request: 2: file_get_contents(https://www.domain.com/inc/upload/jobs/1428/mobile/detail_jobs1428_Banner op hotel site-3.jpg): failed to open stream: HTTP request failed! HTTP/1.1 400 BAD_REQUEST
, Bad Request (tried: fopen) (in /public_html/wire/core/WireHttp.php line 703)
#0 /public_html/wire/core/Pagefile.php(144): ProcessWire\WireHttp->download('https://www....', '/public...')
#1 /public_html/wire/core/Pageimage.php(1246): ProcessWire\Pagefile->___install('https://www....')
#2 /public_html/wire/core/Wire.php(383): ProcessWire\Pageimage->___install('https://www....')
This error message was shown because: you are logged in as a Superuser. Error has been logged.
Optional: Suggestion for a possible fix
I think the escaped URL is being parsed by ProcessWire before the actual download starts. This results in an invalid URL with spaces.
Steps to reproduce the issue
Try to set the image URL above through the API.
Setup/Environment
CentOS 7, NGINX, php-fpm
ProcessWire version: 3.0.98
(Optional) PHP version: 7.2
(Optional) MySQL version: MySQL (latest)
The text was updated successfully, but these errors were encountered: