upload large file using chunks
This commit is contained in:
parent
8ca9210308
commit
fc96625fd5
1 changed files with 21 additions and 17 deletions
|
@ -287,7 +287,7 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
|||
|
||||
$file = $request->getFiles('file');
|
||||
|
||||
/*
|
||||
/**
|
||||
* Validators
|
||||
*/
|
||||
$allowedFileExtensions = $bucket->getAttribute('allowedFileExtensions', []);
|
||||
|
@ -365,7 +365,7 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
|||
// Save to storage
|
||||
$size = $size ?? $device->getFileSize($fileTmpName);
|
||||
$path = $device->getPath($uploadId . '.' . \pathinfo($fileName, PATHINFO_EXTENSION));
|
||||
$path = $bucket->getId() . $path;
|
||||
$path = str_ireplace($device->getRoot(), $device->getRoot() . DIRECTORY_SEPARATOR . $bucket->getId(), $path);
|
||||
|
||||
$file = $dbForInternal->getDocument('files', $uploadId);
|
||||
|
||||
|
@ -395,6 +395,7 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
|||
}
|
||||
|
||||
// Compression
|
||||
if($size <= APP_LIMIT_COMPRESSION || $size <= APP_LIMIT_ENCRYPTION) {
|
||||
$data = $device->read($path);
|
||||
if ($size <= APP_LIMIT_COMPRESSION) {
|
||||
$compressor = new GZIP();
|
||||
|
@ -406,10 +407,11 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
|||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$data = OpenSSL::encrypt($data, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag);
|
||||
}
|
||||
|
||||
if (!$device->write($path, $data, $mimeType)) {
|
||||
throw new Exception('Failed to save file', 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$sizeActual = $device->getFileSize($path);
|
||||
|
||||
|
@ -975,6 +977,8 @@ App::delete('/v1/storage/buckets/:bucketId/files/:fileId')
|
|||
if (!$dbForInternal->deleteDocument('files', $fileId)) {
|
||||
throw new Exception('Failed to remove file from DB', 500);
|
||||
}
|
||||
} else {
|
||||
throw new Exception('Failed to delete file from device', 500);
|
||||
}
|
||||
|
||||
$audits
|
||||
|
|
Loading…
Reference in a new issue