WConverhpClient

WConverhpClient

new WConverhpClient(opt) → {Object}

Description:
  • 建立Hapi使用者(Node.js與Browser)端物件

Source:
Example
import path from 'path'
import fs from 'fs'
import _ from 'lodash-es'
import w from 'wsemi'
import FormData from 'form-data'
import WConverhpClient from './src/WConverhpClient.mjs'

let ms = []

let opt = {
    FormData,
    url: 'http://localhost:8080',
    apiName: 'api',
    getToken: () => {
        return 'token-for-test'
    },
}

//new
let wo = new WConverhpClient(opt)

wo.on('error', (err) => {
    console.log(`error`, err)
})

function downloadLargeFile() {
    let core = async() => {

        await wo.download('id-for-file',
            function ({ prog, p, m }) {
                // console.log('client web: download: prog', prog, p, m)
                if (m === 'download') {
                    console.log('client web: download: prog', prog)
                }
            },
            {
                fdDownload: './', //於nodejs環境才能提供
            })
            .then(function(res) {
                console.log('client web: download: then', res)
                ms.push({ 'download output': res })
            })
            .catch(function (err) {
                console.log('client web: download: catch', err)
            })

        console.log('ms', ms)

    }
    core()
}

downloadLargeFile()
Parameters:
Name Type Description
opt Object

輸入設定參數物件

Properties
Name Type Attributes Default Description
url String <optional>
'http://localhost:8080'

輸入Hapi伺服器網址,預設為'http://localhost:8080'

apiName String <optional>
'api'

輸入API名稱字串,預設'api'

getToken function <optional>
()=>''

輸入取得使用者token的回調函數,預設()=>''

tokenType String <optional>
'Bearer'

輸入token類型字串,預設'Bearer'

sizeSlice Integer <optional>
1024*1024

輸入切片上傳檔案之切片檔案大小整數,單位為Byte,預設為1024*1024

retry Integer <optional>
3

輸入傳輸失敗重試次數整數,預設為3

Returns:

回傳事件物件,可使用函數execute、upload

Type
Object