Skip to content

Commit 21d153a

Browse files
committed
fix(previews): Allow to parse big files for previews
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
1 parent 9b29df2 commit 21d153a

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

config/config.sample.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,6 +2320,18 @@
23202320
*/
23212321
'files_external_allow_create_new_local' => true,
23222322

2323+
/**
2324+
* Controls whether to attempt downloading the entire file for preview generation
2325+
* on non-local storage (e.g., S3, WebDAV) when the initial 5 MB chunk fails to provide
2326+
* sufficient data for a preview. By default, only the first 5 MB of a file is parsed.
2327+
*
2328+
* Enabling this option may significantly increase bandwidth usage and processing time
2329+
* for large files on external storages.
2330+
*
2331+
* * Defaults to ``false``
2332+
*/
2333+
'files_external_full_previews' => false,
2334+
23232335
/**
23242336
* Specifies how often the local filesystem (the Nextcloud data/ directory, and
23252337
* NFS mounts in data/) is checked for changes made outside Nextcloud. This

lib/private/Preview/Movie.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
class Movie extends ProviderV2 {
2020
private IConfig $config;
21-
2221
private ?string $binary = null;
2322

2423
public function __construct(array $options = []) {
@@ -57,11 +56,10 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
5756
// Try downloading 5 MB first, as it's likely that the first frames are present there.
5857
// In some cases this doesn't work, for example when the moov atom is at the
5958
// end of the file, so if it fails we fall back to getting the full file.
60-
// Unless the file is not local (e.g. S3) as we do not want to download the whole (e.g. 37Gb) file
61-
if ($file->getStorage()->isLocal()) {
62-
$sizeAttempts = [5242880, null];
63-
} else {
64-
$sizeAttempts = [5242880];
59+
$sizeAttempts = [5242880];
60+
$fullPreviews = $this->config->getSystemValueBool('files_external_full_previews', false);
61+
if ($file->getStorage()->isLocal() || $fullPreviews === true) {
62+
$sizeAttempts[] = null;
6563
}
6664
} else {
6765
// size is irrelevant, only attempt once

0 commit comments

Comments
 (0)