Merge remote-tracking branch 'origin/cl-1.4.x' into feat-1.4.x-response-filters
This commit is contained in:
commit
0094ced967
4 changed files with 62 additions and 0 deletions
|
@ -313,6 +313,11 @@ return [
|
|||
],
|
||||
|
||||
/** Storage */
|
||||
Exception::STORAGE_FILE_ALREADY_EXISTS => [
|
||||
'name' => Exception::STORAGE_FILE_ALREADY_EXISTS,
|
||||
'description' => 'A storage file with the requested ID already exists.',
|
||||
'code' => 409,
|
||||
],
|
||||
Exception::STORAGE_FILE_NOT_FOUND => [
|
||||
'name' => Exception::STORAGE_FILE_NOT_FOUND,
|
||||
'description' => 'The requested file could not be found.',
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Appwrite\Auth\Auth;
|
||||
use Appwrite\Auth\Hash\Sha;
|
||||
use Appwrite\ClamAV\Network;
|
||||
use Appwrite\Event\Delete;
|
||||
use Appwrite\Event\Event;
|
||||
|
@ -501,13 +502,20 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
|||
$metadata = ['content_type' => $deviceLocal->getFileMimeType($fileTmpName)];
|
||||
if (!$file->isEmpty()) {
|
||||
$chunks = $file->getAttribute('chunksTotal', 1);
|
||||
$uploaded = $file->getAttribute('chunksUploaded', 0);
|
||||
$metadata = $file->getAttribute('metadata', []);
|
||||
|
||||
if ($chunk === -1) {
|
||||
$chunk = $chunks;
|
||||
}
|
||||
|
||||
if ($uploaded === $chunks) {
|
||||
throw new Exception(Exception::STORAGE_FILE_ALREADY_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
$chunksUploaded = $deviceFiles->upload($fileTmpName, $path, $chunk, $chunks, $metadata);
|
||||
|
||||
if (empty($chunksUploaded)) {
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed uploading file');
|
||||
}
|
||||
|
|
|
@ -105,6 +105,7 @@ class Exception extends \Exception
|
|||
public const AVATAR_ICON_NOT_FOUND = 'avatar_icon_not_found';
|
||||
|
||||
/** Storage */
|
||||
public const STORAGE_FILE_ALREADY_EXISTS = 'storage_file_already_exists';
|
||||
public const STORAGE_FILE_NOT_FOUND = 'storage_file_not_found';
|
||||
public const STORAGE_DEVICE_NOT_FOUND = 'storage_device_not_found';
|
||||
public const STORAGE_FILE_EMPTY = 'storage_file_empty';
|
||||
|
|
|
@ -316,6 +316,54 @@ trait StorageBase
|
|||
return ['bucketId' => $bucketId];
|
||||
}
|
||||
|
||||
public function testCreateBucketFileNoCollidingId(): void
|
||||
{
|
||||
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'bucketId' => ID::unique(),
|
||||
'name' => 'Test Bucket',
|
||||
'maximumFileSize' => 2000000, //2MB
|
||||
'allowedFileExtensions' => ["jpg", "png"],
|
||||
'permissions' => [
|
||||
Permission::read(Role::any()),
|
||||
Permission::create(Role::any()),
|
||||
Permission::update(Role::any()),
|
||||
Permission::delete(Role::any()),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $bucket['headers']['status-code']);
|
||||
$this->assertNotEmpty($bucket['body']['$id']);
|
||||
|
||||
$bucketId = $bucket['body']['$id'];
|
||||
|
||||
$fileId = ID::unique();
|
||||
|
||||
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([
|
||||
'content-type' => 'multipart/form-data',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'fileId' => $fileId,
|
||||
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'),
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $file['headers']['status-code']);
|
||||
$this->assertEquals($fileId, $file['body']['$id']);
|
||||
|
||||
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([
|
||||
'content-type' => 'multipart/form-data',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'fileId' => $fileId,
|
||||
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/file.png'), 'image/png', 'file.png'),
|
||||
]);
|
||||
|
||||
$this->assertEquals(409, $file['headers']['status-code']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateBucketFile
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue