ImageCodecException: Failed to detect image file format

Hi,

I am using a docker installation in version 5.5.65.
When I upload an image file, I get an error message saying:

ImageCodecException: Failed to detect image file format using the file header. File header was empty.

However, the image is uploaded correclty and is available via the download url. So I guess it is just missing the preview.

I then tried several other files. PDF, PNG, JPG, JPEG and SVG. This resulted in empty previews and it shows filesize: 0KB.

The Download URL does not work in this case and when I tried to delete these images, I received this error:

400: No query results for model [App\Models\Document].

What have I done wrong?

There is no error in the production log. The laravel log shows this error when trying to upload a file where the preview fails.

[2023-02-03 08:14:41] production.ERROR: file_get_contents(https://crm.ecomsilio.de/storage/bWzSb15UdCi27L95Z9g0lG3u1QO8NX3W/documents/ebUXk75gNjl4uNSlLgnYVD5qbvLngMreenYGvIBK.jpg): Failed to open stream: Connection refused {"userId":1,"exception":"[object] (ErrorException(code: 0): file_get_contents(https://crm.ecomsilio.de/storage/bWzSb15UdCi27L95Z9g0lG3u1QO8NX3W/documents/ebUXk75gNjl4uNSlLgnYVD5qbvLngMreenYGvIBK.jpg): Failed to open stream: Connection refused at /var/www/app/app/Http/Controllers/DocumentController.php:125)
[stacktrace]
#0 /var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(266): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /var/www/app/app/Http/Controllers/DocumentController.php(125): file_get_contents()
#3 /var/www/app/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(145): App\\Http\\Controllers\\DocumentController->App\\Http\\Controllers\\{closure}()
#4 /var/www/app/vendor/symfony/http-foundation/StreamedResponse.php(92): Illuminate\\Routing\\ResponseFactory->Illuminate\\Routing\\{closure}()
#5 /var/www/app/vendor/symfony/http-foundation/Response.php(377): Symfony\\Component\\HttpFoundation\\StreamedResponse->sendContent()
#6 /var/www/app/public/index.php(61): Symfony\\Component\\HttpFoundation\\Response->send()
#7 {main}
"} 

These errors appear when a file is uploaded with 0KB filesize.

[2023-02-03 08:16:13] production.ERROR: file_get_contents(https://crm.ecomsilio.de/storage/bWzSb15UdCi27L95Z9g0lG3u1QO8NX3W/documents/qsk0nMLpfzRbpgE4x0Ow3V3b8v7s3QPpGfkMz51G.jpg): Failed to open stream: Connection refused {"userId":1,"exception":"[object] (ErrorException(code: 0): file_get_contents(https://crm.ecomsilio.de/storage/bWzSb15UdCi27L95Z9g0lG3u1QO8NX3W/documents/qsk0nMLpfzRbpgE4x0Ow3V3b8v7s3QPpGfkMz51G.jpg): Failed to open stream: Connection refused at /var/www/app/app/Http/Controllers/DocumentController.php:125)
[stacktrace]
#0 /var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(266): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /var/www/app/app/Http/Controllers/DocumentController.php(125): file_get_contents()
#3 /var/www/app/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(145): App\\Http\\Controllers\\DocumentController->App\\Http\\Controllers\\{closure}()
#4 /var/www/app/vendor/symfony/http-foundation/StreamedResponse.php(92): Illuminate\\Routing\\ResponseFactory->Illuminate\\Routing\\{closure}()
#5 /var/www/app/vendor/symfony/http-foundation/Response.php(377): Symfony\\Component\\HttpFoundation\\StreamedResponse->sendContent()
#6 /var/www/app/public/index.php(61): Symfony\\Component\\HttpFoundation\\Response->send()
#7 {main}
"} 
[2023-02-03 08:16:13] production.ERROR: file_get_contents(https://crm.ecomsilio.de/storage/bWzSb15UdCi27L95Z9g0lG3u1QO8NX3W/documents/6lClNvCdlRZdnEDQZQ7CwERqfmDcKrm2F0xzc7NQ.jpg): Failed to open stream: Connection refused {"userId":1,"exception":"[object] (ErrorException(code: 0): file_get_contents(https://crm.ecomsilio.de/storage/bWzSb15UdCi27L95Z9g0lG3u1QO8NX3W/documents/6lClNvCdlRZdnEDQZQ7CwERqfmDcKrm2F0xzc7NQ.jpg): Failed to open stream: Connection refused at /var/www/app/app/Http/Controllers/DocumentController.php:125)
[stacktrace]
#0 /var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(266): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /var/www/app/app/Http/Controllers/DocumentController.php(125): file_get_contents()
#3 /var/www/app/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(145): App\\Http\\Controllers\\DocumentController->App\\Http\\Controllers\\{closure}()
#4 /var/www/app/vendor/symfony/http-foundation/StreamedResponse.php(92): Illuminate\\Routing\\ResponseFactory->Illuminate\\Routing\\{closure}()
#5 /var/www/app/vendor/symfony/http-foundation/Response.php(377): Symfony\\Component\\HttpFoundation\\StreamedResponse->sendContent()
#6 /var/www/app/public/index.php(61): Symfony\\Component\\HttpFoundation\\Response->send()
#7 {main}
"} 
[2023-02-03 08:16:13] production.ERROR: file_get_contents(https://crm.ecomsilio.de/storage/bWzSb15UdCi27L95Z9g0lG3u1QO8NX3W/documents/ebUXk75gNjl4uNSlLgnYVD5qbvLngMreenYGvIBK.jpg): Failed to open stream: Connection refused {"userId":1,"exception":"[object] (ErrorException(code: 0): file_get_contents(https://crm.ecomsilio.de/storage/bWzSb15UdCi27L95Z9g0lG3u1QO8NX3W/documents/ebUXk75gNjl4uNSlLgnYVD5qbvLngMreenYGvIBK.jpg): Failed to open stream: Connection refused at /var/www/app/app/Http/Controllers/DocumentController.php:125)
[stacktrace]
#0 /var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(266): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /var/www/app/app/Http/Controllers/DocumentController.php(125): file_get_contents()
#3 /var/www/app/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(145): App\\Http\\Controllers\\DocumentController->App\\Http\\Controllers\\{closure}()
#4 /var/www/app/vendor/symfony/http-foundation/StreamedResponse.php(92): Illuminate\\Routing\\ResponseFactory->Illuminate\\Routing\\{closure}()
#5 /var/www/app/vendor/symfony/http-foundation/Response.php(377): Symfony\\Component\\HttpFoundation\\StreamedResponse->sendContent()
#6 /var/www/app/public/index.php(61): Symfony\\Component\\HttpFoundation\\Response->send()
#7 {main}
"} 
[2023-02-03 08:16:13] production.ERROR: file_get_contents(https://crm.ecomsilio.de/storage/bWzSb15UdCi27L95Z9g0lG3u1QO8NX3W/documents/ROLpOUtluoXwPNAHi69bHUi5fXLFCLopjfzDl4Sw.png): Failed to open stream: Connection refused {"userId":1,"exception":"[object] (ErrorException(code: 0): file_get_contents(https://crm.ecomsilio.de/storage/bWzSb15UdCi27L95Z9g0lG3u1QO8NX3W/documents/ROLpOUtluoXwPNAHi69bHUi5fXLFCLopjfzDl4Sw.png): Failed to open stream: Connection refused at /var/www/app/app/Http/Controllers/DocumentController.php:125)
[stacktrace]
#0 /var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(266): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /var/www/app/app/Http/Controllers/DocumentController.php(125): file_get_contents()
#3 /var/www/app/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(145): App\\Http\\Controllers\\DocumentController->App\\Http\\Controllers\\{closure}()
#4 /var/www/app/vendor/symfony/http-foundation/StreamedResponse.php(92): Illuminate\\Routing\\ResponseFactory->Illuminate\\Routing\\{closure}()
#5 /var/www/app/vendor/symfony/http-foundation/Response.php(377): Symfony\\Component\\HttpFoundation\\StreamedResponse->sendContent()
#6 /var/www/app/public/index.php(61): Symfony\\Component\\HttpFoundation\\Response->send()
#7 {main}
"} 
[2023-02-03 08:16:13] production.ERROR: file_get_contents(https://crm.ecomsilio.de/storage/bWzSb15UdCi27L95Z9g0lG3u1QO8NX3W/documents/LVOTLAIGfxyCQ09QNb1tBqAZvTIYJxCakLDP3J4l.png): Failed to open stream: Connection refused {"userId":1,"exception":"[object] (ErrorException(code: 0): file_get_contents(https://crm.ecomsilio.de/storage/bWzSb15UdCi27L95Z9g0lG3u1QO8NX3W/documents/LVOTLAIGfxyCQ09QNb1tBqAZvTIYJxCakLDP3J4l.png): Failed to open stream: Connection refused at /var/www/app/app/Http/Controllers/DocumentController.php:125)
[stacktrace]
#0 /var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(266): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /var/www/app/app/Http/Controllers/DocumentController.php(125): file_get_contents()
#3 /var/www/app/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(145): App\\Http\\Controllers\\DocumentController->App\\Http\\Controllers\\{closure}()
#4 /var/www/app/vendor/symfony/http-foundation/StreamedResponse.php(92): Illuminate\\Routing\\ResponseFactory->Illuminate\\Routing\\{closure}()
#5 /var/www/app/vendor/symfony/http-foundation/Response.php(377): Symfony\\Component\\HttpFoundation\\StreamedResponse->sendContent()
#6 /var/www/app/public/index.php(61): Symfony\\Component\\HttpFoundation\\Response->send()
#7 {main}
"} 

There are no error when trying to delete a file, except from the error displayed in the app.

Many thanks,
Gijs

OK, ignore the error 400. That happens just because I tried to delete a file that already was deleted before.

The issue here is, that the file is still being displayed but doesn’t exist anymore. A browser refresh doesn’t help. Files are still displayed allthough not available anymore.
Docker recreate does not help.
But when I upload a new file, than all deleted files are gone.

Ok, sorry to bother this much but ignore the error 400 complety.

After a files is deleted, it is important to hit the save button. It then refreshes the page and all deleted files disappear.

So the “only” issue is with the preview and the 0kb files.

Thanks a lot!
Gijs

@ecomsilio

Is this is a recent issue?

The hint in the logs is the connection refused message that it appears your system cannot connect to itself.

you may want to sh into the container and try wget from inside there. I’m not a pro at docker, however you may need to add your domain to the hosts file in the config/hosts?

Hi @david

Thanks, I am not sure if this issue is new as I didn’t try to upload images before.
The domain is already in the hosts file. We had these issues with the logo not being displayed.

But I will ask @Access-InTech to have a look at it.

Many thanks,
Gijs

Hi,

in this case, the host’s /etc/hosts file seamed to cause the issue.

It had an entry like this:

127.0.0.1 localhost crm.ecomsilio.de

So the docker containers assoziated the the domain name crm.ecomsilio.de always with the ip address 127.0.0.1. I guess this could be prevented by modifying the hosts file within the containers to overwrite this behavior. Currently, I’m not sure about the priority of each individual hosts file.

1 Like