diff --git a/src/Storage/Device/S3.php b/src/Storage/Device/S3.php index 7b6161c7..a8447b98 100644 --- a/src/Storage/Device/S3.php +++ b/src/Storage/Device/S3.php @@ -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; } @@ -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); @@ -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, 'headers['content-type'] ?? '') !== 'image/svg+xml')) { + if ($decode && ((isset($response->headers['content-type']) && $response->headers['content-type'] == 'application/xml') || (str_starts_with($response->body, 'headers['content-type'] ?? '') !== 'image/svg+xml'))) { $response->body = \simplexml_load_string($response->body); $response->body = json_decode(json_encode($response->body), true); } diff --git a/tests/Storage/S3Base.php b/tests/Storage/S3Base.php index dd82daea..cf17d915 100644 --- a/tests/Storage/S3Base.php +++ b/tests/Storage/S3Base.php @@ -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 diff --git a/tests/resources/disk-a/config.xml b/tests/resources/disk-a/config.xml new file mode 100644 index 00000000..b2524092 --- /dev/null +++ b/tests/resources/disk-a/config.xml @@ -0,0 +1,23 @@ + + + + Charter Group +
+ 100 Main + Framingham + MA + 01701 +
+
+ 720 Prospect + Framingham + MA + 01701 +
+
+ 120 Ridge + MA + 01760 +
+
+
\ No newline at end of file