$mimeType = $this->attachment->fileType;
$filesize = $this->attachment->filesize;
$location = $this->attachment->getLocation();
+ $this->eTag = $this->attachmentID;
}
+ // unsaved attachments may be cached by the browser for up to 5 minutes only
+ $cacheDuration = ($this->attachment->tmpHash) ? 300 : 31536000;
+
// init file reader
- $this->fileReader = new FileReader($location, array(
+ $this->fileReader = new FileReader($location, [
'filename' => $this->attachment->filename,
'mimeType' => $mimeType,
'filesize' => $filesize,
- 'showInline' => (in_array($mimeType, self::$inlineMimeTypes)),
- 'enableRangeSupport' => (!$this->tiny && !$this->thumbnail),
+ 'showInline' => in_array($mimeType, self::$inlineMimeTypes),
+ 'enableRangeSupport' => !$this->tiny && !$this->thumbnail,
'lastModificationTime' => $this->attachment->uploadTime,
- 'expirationDate' => TIME_NOW + 31536000,
- 'maxAge' => 31536000
+ 'expirationDate' => TIME_NOW + $cacheDuration,
+ 'maxAge' => $cacheDuration
- ));
+ ]);
- // add etag for non-thumbnail
- if (!$this->thumbnail && !$this->tiny) {
- $this->fileReader->addHeader('ETag', '"'.$this->attachmentID.'"');
+ if ($this->eTag !== null) {
+ $this->fileReader->addHeader('ETag', '"'.$this->eTag.'"');
}
}