@@ -2,6 +2,7 @@ import { Service } from '../service';
2
2
import { AppwriteException , Client } from '../client' ;
3
3
import type { Models } from '../models' ;
4
4
import type { UploadProgress , Payload } from '../client' ;
5
+ import fs from 'react-native-fs'
5
6
6
7
export class Storage extends Service {
7
8
@@ -68,12 +69,12 @@ export class Storage extends Service {
68
69
*
69
70
* @param {string } bucketId
70
71
* @param {string } fileId
71
- * @param {File } file
72
+ * @param {any } file
72
73
* @param {string[] } permissions
73
74
* @throws {AppwriteException }
74
75
* @returns {Promise }
75
76
*/
76
- async createFile ( bucketId : string , fileId : string , file : File , permissions ?: string [ ] , onProgress = ( progress : UploadProgress ) => { } ) : Promise < Models . File > {
77
+ async createFile ( bucketId : string , fileId : string , file : any , permissions ?: string [ ] , onProgress = ( progress : UploadProgress ) => { } ) : Promise < Models . File > {
77
78
if ( typeof bucketId === 'undefined' ) {
78
79
throw new AppwriteException ( 'Missing required parameter: "bucketId"' ) ;
79
80
}
@@ -103,10 +104,6 @@ export class Storage extends Service {
103
104
104
105
const uri = new URL ( this . client . config . endpoint + apiPath ) ;
105
106
106
- if ( ! ( file instanceof File ) ) {
107
- throw new AppwriteException ( 'Parameter "file" has to be a File.' ) ;
108
- }
109
-
110
107
const size = file . size ;
111
108
112
109
if ( size <= Service . CHUNK_SIZE ) {
@@ -137,8 +134,9 @@ export class Storage extends Service {
137
134
apiHeaders [ 'x-appwrite-id' ] = response . $id ;
138
135
}
139
136
140
- const chunk = file . slice ( offset , end + 1 ) ;
141
- payload [ 'file' ] = new File ( [ chunk ] , file . name ) ;
137
+ let chunk = await fs . read ( file . uri , Service . CHUNK_SIZE , offset , 'base64' ) ;
138
+
139
+ payload [ 'file' ] = { uri : `data:${ file . type } ;base64,${ chunk } ` , name : file . name , type : file . type } ;
142
140
response = await this . client . call ( 'post' , uri , apiHeaders , payload ) ;
143
141
144
142
if ( onProgress ) {
0 commit comments