MCPcopy Index your code
hub / github.com/appwrite/sdk-for-react-native / createFile

Method createFile

src/services/storage.ts:124–234  ·  view source on GitHub ↗
(
        paramsOrFirst: { bucketId: string, fileId: string, file: {name: string, type: string, size: number, uri: string}, permissions?: string[], onProgress?: (progress: UploadProgress) => void  } | string,
        ...rest: [(string)?, ({name: string, type: string, size: number, uri: string})?, (string[])?,((progress: UploadProgress) => void)?]    
    )

Source from the content-addressed store, hash-verified

122 */
123 async createFile(bucketId: string, fileId: string, file: {name: string, type: string, size: number, uri: string}, permissions?: string[], onProgress?: (progress: UploadProgress) => void): Promise<Models.File>;
124 async createFile(
125 paramsOrFirst: { bucketId: string, fileId: string, file: {name: string, type: string, size: number, uri: string}, permissions?: string[], onProgress?: (progress: UploadProgress) => void } | string,
126 ...rest: [(string)?, ({name: string, type: string, size: number, uri: string})?, (string[])?,((progress: UploadProgress) => void)?]
127 ): Promise<Models.File> {
128 let params: { bucketId: string, fileId: string, file: {name: string, type: string, size: number, uri: string}, permissions?: string[] };
129 let onProgress: ((progress: UploadProgress) => void);
130
131 if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
132 params = (paramsOrFirst || {}) as { bucketId: string, fileId: string, file: {name: string, type: string, size: number, uri: string}, permissions?: string[] };
133 onProgress = paramsOrFirst?.onProgress as ((progress: UploadProgress) => void);
134 } else {
135 params = {
136 bucketId: paramsOrFirst as string,
137 fileId: rest[0] as string,
138 file: rest[1] as {name: string, type: string, size: number, uri: string},
139 permissions: rest[2] as string[]
140 };
141 onProgress = rest[3] as ((progress: UploadProgress) => void);
142 }
143
144 const bucketId = params.bucketId;
145 const fileId = params.fileId;
146 const file = params.file;
147 const permissions = params.permissions;
148
149 if (typeof bucketId === 'undefined') {
150 throw new AppwriteException('Missing required parameter: "bucketId"');
151 }
152
153 if (typeof fileId === 'undefined') {
154 throw new AppwriteException('Missing required parameter: "fileId"');
155 }
156
157 if (typeof file === 'undefined') {
158 throw new AppwriteException('Missing required parameter: "file"');
159 }
160
161 const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
162 const payload: Payload = {};
163
164 if (typeof fileId !== 'undefined') {
165 payload['fileId'] = fileId;
166 }
167
168 if (typeof file !== 'undefined') {
169 payload['file'] = file;
170 }
171
172 if (typeof permissions !== 'undefined') {
173 payload['permissions'] = permissions;
174 }
175
176 const uri = new URL(this.client.config.endpoint + apiPath);
177
178 const size = file.size;
179
180 if (size <= Service.CHUNK_SIZE) {
181 return this.client.call('post', uri, {

Callers

nothing calls this directly

Calls 1

callMethod · 0.80

Tested by

no test coverage detected