Merge pull request #5624 from appwrite/feat-update-file-name
Update file name
This commit is contained in:
commit
2fd347dced
8 changed files with 14 additions and 8 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1268,13 +1268,14 @@ App::put('/v1/storage/buckets/:bucketId/files/:fileId')
|
||||||
->label('sdk.response.model', Response::MODEL_FILE)
|
->label('sdk.response.model', Response::MODEL_FILE)
|
||||||
->param('bucketId', '', new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](/docs/server/storage#createBucket).')
|
->param('bucketId', '', new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](/docs/server/storage#createBucket).')
|
||||||
->param('fileId', '', new UID(), 'File unique ID.')
|
->param('fileId', '', new UID(), 'File unique ID.')
|
||||||
|
->param('name', null, new Text(255), 'Name of the file', true)
|
||||||
->param('permissions', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE, [Database::PERMISSION_READ, Database::PERMISSION_UPDATE, Database::PERMISSION_DELETE, Database::PERMISSION_WRITE]), 'An array of permission string. By default, the current permissions are inherited. [Learn more about permissions](/docs/permissions).', true)
|
->param('permissions', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE, [Database::PERMISSION_READ, Database::PERMISSION_UPDATE, Database::PERMISSION_DELETE, Database::PERMISSION_WRITE]), 'An array of permission string. By default, the current permissions are inherited. [Learn more about permissions](/docs/permissions).', true)
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('dbForProject')
|
->inject('dbForProject')
|
||||||
->inject('user')
|
->inject('user')
|
||||||
->inject('mode')
|
->inject('mode')
|
||||||
->inject('events')
|
->inject('events')
|
||||||
->action(function (string $bucketId, string $fileId, ?array $permissions, Response $response, Database $dbForProject, Document $user, string $mode, Event $events) {
|
->action(function (string $bucketId, string $fileId, ?string $name, ?array $permissions, Response $response, Database $dbForProject, Document $user, string $mode, Event $events) {
|
||||||
|
|
||||||
$bucket = Authorization::skip(fn () => $dbForProject->getDocument('buckets', $bucketId));
|
$bucket = Authorization::skip(fn () => $dbForProject->getDocument('buckets', $bucketId));
|
||||||
|
|
||||||
|
@ -1330,6 +1331,10 @@ App::put('/v1/storage/buckets/:bucketId/files/:fileId')
|
||||||
|
|
||||||
$file->setAttribute('$permissions', $permissions);
|
$file->setAttribute('$permissions', $permissions);
|
||||||
|
|
||||||
|
if (!is_null($name)) {
|
||||||
|
$file->setAttribute('name', $name);
|
||||||
|
}
|
||||||
|
|
||||||
if ($fileSecurity && !$valid) {
|
if ($fileSecurity && !$valid) {
|
||||||
try {
|
try {
|
||||||
$file = $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file);
|
$file = $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file);
|
||||||
|
|
|
@ -706,6 +706,7 @@ trait StorageBase
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
], $this->getHeaders()), [
|
], $this->getHeaders()), [
|
||||||
|
'name' => 'logo_updated.png',
|
||||||
'permissions' => [
|
'permissions' => [
|
||||||
Permission::read(Role::user($this->getUser()['$id'])),
|
Permission::read(Role::user($this->getUser()['$id'])),
|
||||||
Permission::update(Role::user($this->getUser()['$id'])),
|
Permission::update(Role::user($this->getUser()['$id'])),
|
||||||
|
@ -717,7 +718,7 @@ trait StorageBase
|
||||||
$this->assertNotEmpty($file['body']['$id']);
|
$this->assertNotEmpty($file['body']['$id']);
|
||||||
$dateValidator = new DatetimeValidator();
|
$dateValidator = new DatetimeValidator();
|
||||||
$this->assertEquals(true, $dateValidator->isValid($file['body']['$createdAt']));
|
$this->assertEquals(true, $dateValidator->isValid($file['body']['$createdAt']));
|
||||||
$this->assertEquals('logo.png', $file['body']['name']);
|
$this->assertEquals('logo_updated.png', $file['body']['name']);
|
||||||
$this->assertEquals('image/png', $file['body']['mimeType']);
|
$this->assertEquals('image/png', $file['body']['mimeType']);
|
||||||
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
||||||
//$this->assertEquals(54944, $file['body']['sizeActual']);
|
//$this->assertEquals(54944, $file['body']['sizeActual']);
|
||||||
|
|
Loading…
Reference in a new issue