Merge pull request #21945 from nextcloud/fix-contact-download-picture

Changed Content-Disposition header to download Contact Photo with correct extension
This commit is contained in:
John Molakvoæ 2020-09-07 08:40:23 +02:00 committed by GitHub
commit 54438c9d26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 6 deletions

View File

@ -103,7 +103,8 @@ class ImageExportPlugin extends ServerPlugin {
try { try {
$file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node); $file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node);
$response->setHeader('Content-Type', $file->getMimeType()); $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->setStatus(200);
$response->setBody($file->getContent()); $response->setBody($file->getContent());

View File

@ -43,7 +43,7 @@ use Sabre\VObject\Reader;
class PhotoCache { class PhotoCache {
/** @var array */ /** @var array */
protected const ALLOWED_CONTENT_TYPES = [ public const ALLOWED_CONTENT_TYPES = [
'image/png' => 'png', 'image/png' => 'png',
'image/jpeg' => 'jpg', 'image/jpeg' => 'jpg',
'image/gif' => 'gif', 'image/gif' => 'gif',

View File

@ -166,7 +166,7 @@ class ImageExportPluginTest extends TestCase {
if ($photo) { if ($photo) {
$file = $this->createMock(ISimpleFile::class); $file = $this->createMock(ISimpleFile::class);
$file->method('getMimeType') $file->method('getMimeType')
->willReturn('imgtype'); ->willReturn('image/jpeg');
$file->method('getContent') $file->method('getContent')
->willReturn('imgdata'); ->willReturn('imgdata');
@ -176,10 +176,10 @@ class ImageExportPluginTest extends TestCase {
$this->response->expects($this->at(3)) $this->response->expects($this->at(3))
->method('setHeader') ->method('setHeader')
->with('Content-Type', 'imgtype'); ->with('Content-Type', 'image/jpeg');
$this->response->expects($this->at(4)) $this->response->expects($this->at(4))
->method('setHeader') ->method('setHeader')
->with('Content-Disposition', 'attachment'); ->with('Content-Disposition', 'attachment; filename=card.jpg');
$this->response->expects($this->once()) $this->response->expects($this->once())
->method('setStatus') ->method('setStatus')

View File

@ -55,7 +55,7 @@ Feature: carddav
Given "admin" uploads the contact "bjoern.vcf" to the addressbook "MyAddressbook" 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" When Exporting the picture of contact "bjoern.vcf" from addressbook "MyAddressbook" as user "admin"
Then The following HTTP headers should be set Then The following HTTP headers should be set
|Content-Disposition|attachment| |Content-Disposition|attachment; filename=bjoern.vcf.jpg|
|Content-Type|image/jpeg| |Content-Type|image/jpeg|
|Content-Security-Policy|default-src 'none';| |Content-Security-Policy|default-src 'none';|
|X-Content-Type-Options |nosniff| |X-Content-Type-Options |nosniff|