MCPcopy Create free account
hub / github.com/appwrite/sdk-for-react-native / updateFile

Method updateFile

src/services/storage.ts:312–357  ·  view source on GitHub ↗
(
        paramsOrFirst: { bucketId: string, fileId: string, name?: string, permissions?: string[] } | string,
        ...rest: [(string)?, (string)?, (string[])?]    
    )

Source from the content-addressed store, hash-verified

310 */
311 updateFile(bucketId: string, fileId: string, name?: string, permissions?: string[]): Promise<Models.File>;
312 updateFile(
313 paramsOrFirst: { bucketId: string, fileId: string, name?: string, permissions?: string[] } | string,
314 ...rest: [(string)?, (string)?, (string[])?]
315 ): Promise<Models.File> {
316 let params: { bucketId: string, fileId: string, name?: string, permissions?: string[] };
317
318 if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
319 params = (paramsOrFirst || {}) as { bucketId: string, fileId: string, name?: string, permissions?: string[] };
320 } else {
321 params = {
322 bucketId: paramsOrFirst as string,
323 fileId: rest[0] as string,
324 name: rest[1] as string,
325 permissions: rest[2] as string[]
326 };
327 }
328
329 const bucketId = params.bucketId;
330 const fileId = params.fileId;
331 const name = params.name;
332 const permissions = params.permissions;
333
334 if (typeof bucketId === 'undefined') {
335 throw new AppwriteException('Missing required parameter: "bucketId"');
336 }
337
338 if (typeof fileId === 'undefined') {
339 throw new AppwriteException('Missing required parameter: "fileId"');
340 }
341
342 const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
343 const payload: Payload = {};
344
345 if (typeof name !== 'undefined') {
346 payload['name'] = name;
347 }
348
349 if (typeof permissions !== 'undefined') {
350 payload['permissions'] = permissions;
351 }
352
353 const uri = new URL(this.client.config.endpoint + apiPath);
354 return this.client.call('put', uri, {
355 'content-type': 'application/json',
356 }, payload);
357 }
358
359 /**
360 * Delete a file by its unique ID. Only users with write permissions have access to delete this resource.

Callers

nothing calls this directly

Calls 1

callMethod · 0.80

Tested by

no test coverage detected