Skip to content

Commit afaa923

Browse files
Merge pull request #31 from ConvertAPI/fix/filenames-with-spaces
Fix filename with spaces encoding in file uploads
2 parents e327504 + 74776d6 commit afaa923

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/ConvertApi/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function upload($file_or_resource, $fileName)
2828
[
2929
'Content-Type: application/octet-stream',
3030
'Transfer-Encoding: chunked',
31-
"Content-Disposition: attachment; filename*=UTF-8''" . urlencode($fileName),
31+
"Content-Disposition: attachment; filename*=UTF-8''" . rawurlencode($fileName),
3232
]
3333
);
3434

tests/ConvertApi/ConvertApiTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ public function testConvertWithFileUpload()
9696
$this->assertEquals('custom.pdf', $result->getFile()->getFileName());
9797
}
9898

99+
public function testConvertWithFileUploadAndSpaces()
100+
{
101+
$fileUpload = new \ConvertApi\FileUpload('examples/files/test.docx', 'test space ačiū.docx');
102+
$params = ['File' => $fileUpload];
103+
104+
$result = ConvertApi::convert('pdf', $params);
105+
106+
$this->assertEquals('test space ačiū.pdf', $result->getFile()->getFileName());
107+
}
108+
99109
public function testConvertWithFileResourceUpload()
100110
{
101111
$fp = fopen('examples/files/test.docx', 'rb');

0 commit comments

Comments
 (0)