file_get_file_contents returns raw binary instead of base64 when raw=false (SOAP always breaks with binary UTF-8 error)

Bug Report Template

Description

file_get_file_contents always returns raw binary instead of base64 when requesting raw=false via SOAP.
This causes SOAP parsing to fail with UTF-8 errors when retrieving images or other binary files.

The issue happens regardless of whether parameters are sent using the WSDL-defined names (file, raw) or the positional parameters (param0, param1).

I am using soap apis from my apiscp server on :2083/soap, and calling them on my node js app.

It appears the SOAP handler is not interpreting the raw parameter correctly, and defaults to raw = true, returning binary data.

Steps to Reproduce

Attempt 1 — Using WSDL-specified parameters

SOAP Body:

<tns:file_get_file_contents>
    <file>/home/user/image.jpg</file>
    <raw>false</raw>
</tns:file_get_file_contents>

Attempt 2 — Using positional parameters

SOAP Body:

<tns:file_get_file_contents>
    <param0>/home/user/image.jpg</param0>
    <param1>false</param1>
</tns:file_get_file_contents>

Result

ApisCP returns raw binary bytes (JPEG header 0xFF 0xD8 0xFF ...) inside XML.

SOAP parser immediately fails with:

SOAP-ERROR: Encoding: string '\xff...' is not a valid utf-8 string

This means ApisCP is not honoring raw=false.

Expected Behavior

When raw=false, based on ApisCP internal implementation:

return $raw ? $contents : base64_encode($contents);

we expect:

  • SOAP response containing base64-encoded file contents
  • No invalid UTF-8 errors

This is necessary for downloading images, videos, or other binary files safely via SOAP.


Actual Behavior

ApisCP returns raw binary contents to the SOAP client even when:

  • <raw>false</raw> is sent, or
  • <param1>false</param1> is sent

This results in invalid UTF-8 sequences inside XML:

SOAP-ERROR: Encoding: string '\xff...' is not a valid utf-8 string

The behavior suggests the raw argument is not being interpreted as a boolean by the SOAP dispatcher.


Environment


Additional Information

WSDL Fragment

<message name="file_get_file_contents_request">
    <part name="file" type="xsd:anyType" />
    <part name="raw"  type="xsd:anyType" />
</message>

<message name="file_get_file_contents_response">
    <part name="return" type="xsd:string" />
</message>

Actual PHP implementation

From ApisCP source:

return $raw ? $contents : base64_encode($contents);

This confirms:

  • raw=true → return binary
  • raw=false → return base64

Yet even with raw=false passed through SOAP, ApisCP behaves as if raw=true.

Error Message

SOAP-ERROR: Encoding: string '\xff...' is not a valid utf-8 string

Parameter type isn’t specified, so it’s treated as a raw string such that false → “false” and a string of non-zero length is true. Type conversions occur within PHP’s SOAP engine, which observe type attributes defined within the SOAP body.

An appropriate call, which explicitly defines data type:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
	xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
	xmlns:ns1="urn:net.apnscp.api"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
	<SOAP-ENV:Body>
		<ns1:file_get_file_contents>
			<file xsi:type="xsd:string">~/index.jpg</file>
			<raw xsi:type="xsd:boolean">false</raw>
		</ns1:file_get_file_contents>
	</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

How are you interacting with the API? Manually generating XML or using a third-party library to interface its WSDL? If the latter, which library and try the changes just now.

rm -f /usr/local/apnscp/public/apnscp.wsdl
cpcmd scope:set cp.update-policy edge-major
upcp
1 Like