Skip to content

Commit

Permalink
Merge pull request #21945 from nextcloud/fix-contact-download-picture
Browse files Browse the repository at this point in the history
Changed Content-Disposition header to download Contact Photo with correct extension
  • Loading branch information
skjnldsv committed Sep 7, 2020
2 parents da8cff9 + e8a4feb commit 54438c9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion apps/dav/lib/CardDAV/ImageExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public function httpGet(RequestInterface $request, ResponseInterface $response)
try {
$file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node);
$response->setHeader('Content-Type', $file->getMimeType());
$response->setHeader('Content-Disposition', 'attachment');
$fileName = $node->getName() . '.' . PhotoCache::ALLOWED_CONTENT_TYPES[$file->getMimeType()];
$response->setHeader('Content-Disposition', "attachment; filename=$fileName");
$response->setStatus(200);

$response->setBody($file->getContent());
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CardDAV/PhotoCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
class PhotoCache {

/** @var array */
protected const ALLOWED_CONTENT_TYPES = [
public const ALLOWED_CONTENT_TYPES = [
'image/png' => 'png',
'image/jpeg' => 'jpg',
'image/gif' => 'gif',
Expand Down
6 changes: 3 additions & 3 deletions apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function testCard($size, $photo) {
if ($photo) {
$file = $this->createMock(ISimpleFile::class);
$file->method('getMimeType')
->willReturn('imgtype');
->willReturn('image/jpeg');
$file->method('getContent')
->willReturn('imgdata');

Expand All @@ -176,10 +176,10 @@ public function testCard($size, $photo) {

$this->response->expects($this->at(3))
->method('setHeader')
->with('Content-Type', 'imgtype');
->with('Content-Type', 'image/jpeg');
$this->response->expects($this->at(4))
->method('setHeader')
->with('Content-Disposition', 'attachment');
->with('Content-Disposition', 'attachment; filename=card.jpg');

$this->response->expects($this->once())
->method('setStatus')
Expand Down
2 changes: 1 addition & 1 deletion build/integration/features/carddav.feature
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Feature: carddav
Given "admin" uploads the contact "bjoern.vcf" to the addressbook "MyAddressbook"
When Exporting the picture of contact "bjoern.vcf" from addressbook "MyAddressbook" as user "admin"
Then The following HTTP headers should be set
|Content-Disposition|attachment|
|Content-Disposition|attachment; filename=bjoern.vcf.jpg|
|Content-Type|image/jpeg|
|Content-Security-Policy|default-src 'none';|
|X-Content-Type-Options |nosniff|
Expand Down

0 comments on commit 54438c9

Please sign in to comment.