Skip to content

Commit e2efc59

Browse files
committed
Handle large file uploads
1 parent f7a1d78 commit e2efc59

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/Command/UploadCommand.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,25 @@ private function uploadFiles(array $files, OutputInterface $output): void
7676
$output->write("Uploading $file... ");
7777
try {
7878
$localFile = __DIR__ . '/../uploads/' . $file;
79-
80-
$client->upload($file, file_get_contents($localFile));
79+
$fileSize = filesize($localFile);
80+
81+
// Dropbox simple upload limit is 150MB
82+
// Use chunked upload for files larger than 150MB
83+
$maxSimpleUploadSize = 150 * 1024 * 1024; // 150MB in bytes
84+
85+
if ($fileSize > $maxSimpleUploadSize) {
86+
// Use chunked upload for large files
87+
// Chunk size of 8MB is recommended for optimal performance
88+
$chunkSize = 8 * 1024 * 1024; // 8MB
89+
$output->write("(large file, using chunked upload) ");
90+
91+
$fileHandle = fopen($localFile, 'r');
92+
$client->uploadChunked($file, $fileHandle, $chunkSize);
93+
fclose($fileHandle);
94+
} else {
95+
// Use simple upload for smaller files
96+
$client->upload($file, file_get_contents($localFile));
97+
}
8198

8299
$output->write("OK");
83100
unlink($localFile);

0 commit comments

Comments
 (0)