|
@@ -27,7 +27,7 @@ describe('Get storage folders', (report, done) => {
|
27
|
27
|
<Assert key="check properties"
|
28
|
28
|
expect={dirs}
|
29
|
29
|
comparer={Comparer.hasProperties}
|
30
|
|
- actual={['PictureDir', 'MovieDir', 'DocumentDir', 'CacheDir']}
|
|
30
|
+ actual={['PictureDir', 'MovieDir', 'DocumentDir', 'CacheDir', 'MusicDir', 'DCIMDir']}
|
31
|
31
|
/>,
|
32
|
32
|
<Info key="System Folders">
|
33
|
33
|
<Text>{`${JSON.stringify(dirs)}`}</Text>
|
|
@@ -46,7 +46,7 @@ describe('Download file to storage with custom file extension', (report, done) =
|
46
|
46
|
fileCache : true,
|
47
|
47
|
appendExt : 'png'
|
48
|
48
|
})
|
49
|
|
- .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
|
|
49
|
+ .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
|
50
|
50
|
.then((resp) => {
|
51
|
51
|
tmpFilePath = resp.path()
|
52
|
52
|
report(<Info key={`image from ${tmpFilePath}`}>
|
|
@@ -65,8 +65,6 @@ describe('Read cached file via file stream', (report, done) => {
|
65
|
65
|
data += chunk
|
66
|
66
|
})
|
67
|
67
|
stream.onEnd(() => {
|
68
|
|
- console.log(prop('image').length, data.length)
|
69
|
|
- console.log(data)
|
70
|
68
|
report(
|
71
|
69
|
<Assert key="image should have value"
|
72
|
70
|
expect={0}
|
|
@@ -95,33 +93,60 @@ describe('File stream reader error should be able to handled', (report, done) =>
|
95
|
93
|
})
|
96
|
94
|
})
|
97
|
95
|
|
98
|
|
-//
|
99
|
|
-// describe('Upload from file storage', (report, done) => {
|
100
|
|
-// let filename = ''
|
101
|
|
-// let filepath = ''
|
102
|
|
-// RNFetchBlob.getSystemDirs().then((dirs) => {
|
103
|
|
-// filename = 'ios.5.0-' + Date.now() + '-from-storage.png'
|
104
|
|
-// filepath = dirs.DocumentDir + '/' + filename
|
105
|
|
-// return RNFetchBlob.config({ path : filepath })
|
106
|
|
-// .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
|
107
|
|
-// })
|
108
|
|
-// .then((resp) => {
|
109
|
|
-// let path = resp.path()
|
110
|
|
-// return RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
|
111
|
|
-// Authorization : `Bearer ${DROPBOX_TOKEN}`,
|
112
|
|
-// 'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+filename+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
|
113
|
|
-// 'Content-Type' : 'application/octet-stream',
|
114
|
|
-// }, 'RNFetchBlob-file://' + path)
|
115
|
|
-// .then((resp) => {
|
116
|
|
-// console.log(resp.text())
|
117
|
|
-// resp = resp.json()
|
118
|
|
-// report(
|
119
|
|
-// <Assert key="confirm the file has been uploaded" expect={filename} actual={resp.name}/>
|
120
|
|
-// )
|
121
|
|
-// done()
|
122
|
|
-// })
|
123
|
|
-// })
|
124
|
|
-//
|
125
|
|
-//
|
126
|
|
-//
|
127
|
|
-// })
|
|
96
|
+let localFile = null
|
|
97
|
+
|
|
98
|
+describe('Upload from file storage', (report, done) => {
|
|
99
|
+ let filename = ''
|
|
100
|
+ let filepath = ''
|
|
101
|
+ RNFetchBlob.getSystemDirs().then((dirs) => {
|
|
102
|
+ filename = Platform.OS + '0.5.0-' + Date.now() + '-from-storage.png'
|
|
103
|
+ filepath = dirs.DocumentDir + '/' + filename
|
|
104
|
+ return RNFetchBlob.config({ path : filepath })
|
|
105
|
+ .fetch('GET', `${TEST_SERVER_URL}/public/github2.jpg`)
|
|
106
|
+ })
|
|
107
|
+ .then((resp) => {
|
|
108
|
+ let path = resp.path()
|
|
109
|
+ localFile = path
|
|
110
|
+ return RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
|
|
111
|
+ Authorization : `Bearer ${DROPBOX_TOKEN}`,
|
|
112
|
+ 'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+filename+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
|
|
113
|
+ 'Content-Type' : 'application/octet-stream',
|
|
114
|
+ }, 'RNFetchBlob-file://' + path)
|
|
115
|
+ .then((resp) => {
|
|
116
|
+ resp = resp.json()
|
|
117
|
+ report(
|
|
118
|
+ <Assert key="confirm the file has been uploaded" expect={filename} actual={resp.name}/>
|
|
119
|
+ )
|
|
120
|
+ done()
|
|
121
|
+ })
|
|
122
|
+ })
|
|
123
|
+})
|
|
124
|
+
|
|
125
|
+describe('Upload multipart data with file from storage', (report, done) => {
|
|
126
|
+ let filename = 'test-from-storage-img-'+Date.now()+'.png'
|
|
127
|
+ RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
|
|
128
|
+ 'Content-Type' : 'multipart/form-data',
|
|
129
|
+ }, [
|
|
130
|
+ { name : 'test-img', filename : filename, data: 'RNFetchBlob-file://' + localFile},
|
|
131
|
+ { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
|
|
132
|
+ { name : 'field1', data : 'hello !!'},
|
|
133
|
+ { name : 'field2', data : 'hello2 !!'}
|
|
134
|
+ ])
|
|
135
|
+ .then((resp) => {
|
|
136
|
+ resp = resp.json()
|
|
137
|
+ report(
|
|
138
|
+ <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
|
|
139
|
+ <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
|
|
140
|
+ )
|
|
141
|
+ return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/${filename}`)
|
|
142
|
+ })
|
|
143
|
+ .then((resp) => {
|
|
144
|
+ report(<Info key="uploaded image">
|
|
145
|
+ <Image
|
|
146
|
+ style={styles.image}
|
|
147
|
+ source={{ uri : 'data:image/png;base64, '+ resp.base64()}}/>
|
|
148
|
+ </Info>)
|
|
149
|
+ done()
|
|
150
|
+ })
|
|
151
|
+
|
|
152
|
+})
|