|
@@ -0,0 +1,76 @@
|
|
1
|
+import RNTest from './react-native-testkit/'
|
|
2
|
+import React from 'react'
|
|
3
|
+import RNFetchBlob from 'react-native-fetch-blob'
|
|
4
|
+import {
|
|
5
|
+ StyleSheet,
|
|
6
|
+ Text,
|
|
7
|
+ View,
|
|
8
|
+ ScrollView,
|
|
9
|
+ Linking,
|
|
10
|
+ Platform,
|
|
11
|
+ Dimensions,
|
|
12
|
+ BackAndroid,
|
|
13
|
+ AsyncStorage,
|
|
14
|
+ Image,
|
|
15
|
+} from 'react-native';
|
|
16
|
+
|
|
17
|
+window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
|
|
18
|
+window.Blob = RNFetchBlob.polyfill.Blob
|
|
19
|
+
|
|
20
|
+const JSONStream = RNFetchBlob.JSONStream
|
|
21
|
+const fs = RNFetchBlob.fs
|
|
22
|
+const { Assert, Comparer, Info, prop } = RNTest
|
|
23
|
+const describe = RNTest.config({
|
|
24
|
+ group : '0.10.1',
|
|
25
|
+ run : true,
|
|
26
|
+ expand : true,
|
|
27
|
+ timeout : 20000,
|
|
28
|
+})
|
|
29
|
+const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
|
|
30
|
+const dirs = RNFetchBlob.fs.dirs
|
|
31
|
+let prefix = ((Platform.OS === 'android') ? 'file://' : '')
|
|
32
|
+let begin = Date.now()
|
|
33
|
+
|
|
34
|
+describe('#177 multipart upload event only triggers once', (report, done) => {
|
|
35
|
+
|
|
36
|
+ try{
|
|
37
|
+ let localFile = null
|
|
38
|
+ let filename = 'dummy-'+Date.now()
|
|
39
|
+ RNFetchBlob.config({
|
|
40
|
+ fileCache : true
|
|
41
|
+ })
|
|
42
|
+ .fetch('GET', `${TEST_SERVER_URL}/public/6mb-dummy`)
|
|
43
|
+ .then((res) => {
|
|
44
|
+ localFile = res.path()
|
|
45
|
+ return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
|
|
46
|
+ 'Content-Type' : 'multipart/form-data',
|
|
47
|
+ }, [
|
|
48
|
+ { name : 'test-img', filename : filename, data: 'RNFetchBlob-file://' + localFile},
|
|
49
|
+ { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
|
|
50
|
+ { name : 'field1', data : 'hello !!'},
|
|
51
|
+ { name : 'field2', data : 'hello2 !!'}
|
|
52
|
+ ])
|
|
53
|
+ .uploadProgress({ interval : 100 },(now, total) => {
|
|
54
|
+ console.log(now/total)
|
|
55
|
+ })
|
|
56
|
+ })
|
|
57
|
+ .then((resp) => {
|
|
58
|
+ resp = resp.json()
|
|
59
|
+ report(
|
|
60
|
+ <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
|
|
61
|
+ <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
|
|
62
|
+ )
|
|
63
|
+ return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/${filename}`)
|
|
64
|
+ })
|
|
65
|
+ .then((resp) => {
|
|
66
|
+ report(<Info key="uploaded image">
|
|
67
|
+ <Image
|
|
68
|
+ style={styles.image}
|
|
69
|
+ source={{ uri : 'data:image/png;base64, '+ resp.base64()}}/>
|
|
70
|
+ </Info>)
|
|
71
|
+ done()
|
|
72
|
+ })
|
|
73
|
+ } catch(err) {
|
|
74
|
+ console.log(err)
|
|
75
|
+ }
|
|
76
|
+})
|