diff --git a/lib/ConvertApi/Client.php b/lib/ConvertApi/Client.php index 2bdef4a..64e2caf 100644 --- a/lib/ConvertApi/Client.php +++ b/lib/ConvertApi/Client.php @@ -26,8 +26,6 @@ public function upload($file_or_resource, $fileName) $headers = array_merge( $this->defaultHeaders(), [ - 'Content-Type: application/octet-stream', - 'Transfer-Encoding: chunked', "Content-Disposition: attachment; filename*=UTF-8''" . rawurlencode($fileName), ] ); diff --git a/tests/ConvertApi/ConvertApiTest.php b/tests/ConvertApi/ConvertApiTest.php index 3005e86..17fb76e 100644 --- a/tests/ConvertApi/ConvertApiTest.php +++ b/tests/ConvertApi/ConvertApiTest.php @@ -48,6 +48,37 @@ public function testGetUser() $this->assertArrayHasKey('SecondsLeft', $user_info); } + public function testUploadFile() + { + $file = 'examples/files/test.docx'; + + $fileContents = file_get_contents($file); + $crc = hash('crc32b', $fileContents); + + $result = ConvertApi::client()->upload($file, 'test.docx'); + $uploadedContents = file_get_contents($result['Url']); + $uploadedCrc = hash('crc32b', $uploadedContents); + + $this->assertEquals($crc, $uploadedCrc); + } + + public function testUploadStream() + { + $file = 'examples/files/test.docx'; + $fileContents = file_get_contents($file); + $crc = hash('crc32b', $fileContents); + + $stream = fopen('php://memory', 'rwb'); + fwrite($stream, $fileContents); + rewind($stream); + + $result = ConvertApi::client()->upload($stream, 'test.docx'); + $uploadedContents = file_get_contents($result['Url']); + $uploadedCrc = hash('crc32b', $uploadedContents); + + $this->assertEquals($crc, $uploadedCrc); + } + public function testConvertWithFileUrl() { $params = ['File' => 'https://cdn.convertapi.com/cara/testfiles/document.docx?test=1'];