Skip to content

Commit

Permalink
'Allow specifying the file's content type, fallback to b2/x-auto
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris White committed Feb 17, 2016
1 parent ea76d14 commit 4eb97c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ public function upload(array $options)
$options['FileLastModified'] = round(microtime(true) * 1000);
}

$options['FileContentType'] = 'application/octet-stream';
if (!isset($options['FileContentType'])) {
$options['FileContentType'] = 'b2/x-auto';
}

$response = $this->client->request('POST', $uploadEndpoint, [
'headers' => [
Expand Down
5 changes: 4 additions & 1 deletion tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public function testUploadingString()
$this->assertInstanceOf(Stream::class, $uploadRequest->getBody());
}

public function testUploadingWithCustomMimeAndLastModified()
public function testUploadingWithCustomContentTypeAndLastModified()
{
$container = [];
$history = Middleware::history($container);
Expand All @@ -284,11 +284,13 @@ public function testUploadingWithCustomMimeAndLastModified()

// My birthday :)
$lastModified = 701568000000;
$contentType = 'text/plain';

$file = $client->upload([
'BucketId' => 'bucketId',
'FileName' => 'test.txt',
'Body' => 'Test file content',
'FileContentType' => $contentType,
'FileLastModified' => $lastModified
]);

Expand All @@ -297,6 +299,7 @@ public function testUploadingWithCustomMimeAndLastModified()
// We'll also check the Guzzle history to make sure the upload request got created correctly.
$uploadRequest = $container[2]['request'];
$this->assertEquals($lastModified, $uploadRequest->getHeader('X-Bz-Info-src_last_modified_millis')[0]);
$this->assertEquals($contentType, $uploadRequest->getHeader('Content-Type')[0]);
$this->assertInstanceOf(Stream::class, $uploadRequest->getBody());
}

Expand Down

0 comments on commit 4eb97c3

Please sign in to comment.