Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Storage/Device/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public function read(string $path, int $offset = 0, int $length = null): string
$end = $offset + $length - 1;
$this->headers['range'] = "bytes=$offset-$end";
}
$response = $this->call(self::METHOD_GET, $uri);
$response = $this->call(self::METHOD_GET, $uri, decode: false);

return $response->body;
}
Expand Down Expand Up @@ -720,11 +720,12 @@ private function getSignatureV4(string $method, string $uri, array $parameters =
* @param string $uri
* @param string $data
* @param array $parameters
* @param bool $decode
* @return object
*
* @throws \Exception
*/
private function call(string $method, string $uri, string $data = '', array $parameters = [])
private function call(string $method, string $uri, string $data = '', array $parameters = [], bool $decode = true)
{
$uri = $this->getAbsolutePath($uri);
$url = 'https://'.$this->headers['host'].$uri.'?'.\http_build_query($parameters, '', '&', PHP_QUERY_RFC3986);
Expand Down Expand Up @@ -810,7 +811,7 @@ private function call(string $method, string $uri, string $data = '', array $par
\curl_close($curl);

// Parse body into XML
if ((isset($response->headers['content-type']) && $response->headers['content-type'] == 'application/xml') || (str_starts_with($response->body, '<?xml') && ($response->headers['content-type'] ?? '') !== 'image/svg+xml')) {
if ($decode && ((isset($response->headers['content-type']) && $response->headers['content-type'] == 'application/xml') || (str_starts_with($response->body, '<?xml') && ($response->headers['content-type'] ?? '') !== 'image/svg+xml'))) {
$response->body = \simplexml_load_string($response->body);
$response->body = json_decode(json_encode($response->body), true);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Storage/S3Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ public function testSVGUpload()
$this->assertEquals(true, $this->object->delete($this->object->getPath('testing/appwrite.svg')));
}

public function testXMLUpload()
{
$this->assertEquals(true, $this->object->upload(__DIR__.'/../resources/disk-a/config.xml', $this->object->getPath('testing/config.xml')));
$this->assertEquals(file_get_contents(__DIR__.'/../resources/disk-a/config.xml'), $this->object->read($this->object->getPath('testing/config.xml')));
$this->assertEquals(true, $this->object->exists($this->object->getPath('testing/config.xml')));
$this->assertEquals(true, $this->object->delete($this->object->getPath('testing/config.xml')));
}

public function testDeletePath()
{
// Test Single Object
Expand Down
23 changes: 23 additions & 0 deletions tests/resources/disk-a/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<customers>
<customer id="55000">
<name>Charter Group</name>
<address>
<street>100 Main</street>
<city>Framingham</city>
<state>MA</state>
<zip>01701</zip>
</address>
<address>
<street>720 Prospect</street>
<city>Framingham</city>
<state>MA</state>
<zip>01701</zip>
</address>
<address>
<street>120 Ridge</street>
<state>MA</state>
<zip>01760</zip>
</address>
</customer>
</customers>