const network = app.requireModule("pmuiNetwork");
let network = requireModuleJs('pmuiNetwork');
download(params, callback) 下载
参数
+ url (String)
+ [headers] (Object)
+ [target] (Object)
返回
+ result (Object)
+ status (Int)
+ statusText (String)
+ ok (Boolean) (status 2xx)
+ headers (String)
+ data (String)
+ progress (Number) (status 100)
+ error (Object) (status -1)
示例
networkTransfer.download('http://cdn.instapp.io/nat/samples/audio.mp3', (ret) => {
console.log(ret)
})
networkTransfer.download({
url: 'http://cdn.instapp.io/nat/samples/audio.mp3',
headers: {
'x-app': 'nat/0.0.8',
'x-sign': 'bfbbf4c1f087d972'
},
target: '/instapp/nat/download'
}, (ret) => {
console.log(ret)
})
upload(params, callback) 上传
参数
+ url (String)
+ path (String)
+ [method] (String) (POST | PUT | PATCH, default: POST)
+ [headers] (Object)
+ [name] (String)
+ [formData] (Object)
+ [mimeType] (String)
返回
+ result (Object)
+ status (Int)
+ statusText (String)
+ ok (Boolean) (status 2xx)
+ headers (String)
+ data (String)
+ progress (Number) (status 100)
+ error (Object) (status -1)
示例
networkTransfer.upload({
url:'http://uploader.示例.com',
path: 'file:///tmp/intapp/nat/sample/localFile'
}, (ret) => {
console.log(ret)
})
networkTransfer.upload({
url: 'http://uploader.示例.com',
path: 'file:///tmp/intapp/nat/sample/localFile',
method: 'PUT',
formData: {
framework: 'weex/nat'
},
headers: {
'x-app': 'nat/0.0.8',
'x-sign': 'bfbbf4c1f087d972'
}
}, (ret) => {
console.log(ret)
})
Error
DOWNLOAD_INTERNAL_ERROR
DOWNLOAD_INVALID_ARGUMENT
DOWNLOAD_NETWORK_ERROR
UPLOAD_INTERNAL_ERROR
UPLOAD_INVALID_ARGUMENT
UPLOAD_NETWORK_ERROR