Skip to content

Commit f3e555d

Browse files
laurynas-convertapiLaurynas Butkus
andauthored
Do not set content type header when uploading file (#57)
Co-authored-by: Laurynas Butkus <laurynas@baltsoft.com>
1 parent a4c67b1 commit f3e555d

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/ConvertApi/Client.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public function upload($file_or_resource, $fileName)
2626
$headers = array_merge(
2727
$this->defaultHeaders(),
2828
[
29-
'Content-Type: application/octet-stream',
30-
'Transfer-Encoding: chunked',
3129
"Content-Disposition: attachment; filename*=UTF-8''" . rawurlencode($fileName),
3230
]
3331
);

tests/ConvertApi/ConvertApiTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,37 @@ public function testGetUser()
4848
$this->assertArrayHasKey('SecondsLeft', $user_info);
4949
}
5050

51+
public function testUploadFile()
52+
{
53+
$file = 'examples/files/test.docx';
54+
55+
$fileContents = file_get_contents($file);
56+
$crc = hash('crc32b', $fileContents);
57+
58+
$result = ConvertApi::client()->upload($file, 'test.docx');
59+
$uploadedContents = file_get_contents($result['Url']);
60+
$uploadedCrc = hash('crc32b', $uploadedContents);
61+
62+
$this->assertEquals($crc, $uploadedCrc);
63+
}
64+
65+
public function testUploadStream()
66+
{
67+
$file = 'examples/files/test.docx';
68+
$fileContents = file_get_contents($file);
69+
$crc = hash('crc32b', $fileContents);
70+
71+
$stream = fopen('php://memory', 'rwb');
72+
fwrite($stream, $fileContents);
73+
rewind($stream);
74+
75+
$result = ConvertApi::client()->upload($stream, 'test.docx');
76+
$uploadedContents = file_get_contents($result['Url']);
77+
$uploadedCrc = hash('crc32b', $uploadedContents);
78+
79+
$this->assertEquals($crc, $uploadedCrc);
80+
}
81+
5182
public function testConvertWithFileUrl()
5283
{
5384
$params = ['File' => 'https://cdn.convertapi.com/cara/testfiles/document.docx?test=1'];

0 commit comments

Comments
 (0)