断点续传示例

golang版本

package main

import (
    "os"
    "fmt"
    "github.com/eventials/go-tus"
)

func main() {
    f, err := os.Open("100m")
    if err != nil {
        panic(err)
    }
    defer f.Close()
    // create the tus client.
    client, err := tus.NewClient("http://10.1.5.9:8080/big/upload/", nil)
    fmt.Println(err)
    // create an upload from a file.
    upload, err := tus.NewUploadFromFile(f)
    fmt.Println(err)
    // create the uploader.
    uploader, err := client.CreateUpload(upload)
    fmt.Println(err)
    // start the uploading process.
   fmt.Println( uploader.Upload())

}

`

javascript版本 更多请查阅


<html>
              <head>
                <meta charset="utf-8" />
                <title>go-fastdfs</title>
                <style>form { bargin } .form-line { display:block;height: 30px;margin:8px; } #stdUpload {background: #fafafa;border-radius: 10px;width: 745px; }</style>
                <link href="https://transloadit.edgly.net/releases/uppy/v0.30.0/dist/uppy.min.css" rel="stylesheet">
              </head>

              <body>
                 <div>断点续传(如果文件很大时可以考虑)</div>
                <div>

                  <div id="drag-drop-area"></div>
                  <script src="https://transloadit.edgly.net/releases/uppy/v0.30.0/dist/uppy.min.js"></script>
                  <script>var uppy = Uppy.Core().use(Uppy.Dashboard, {
                      inline: true,
                      target: '#drag-drop-area'
                    }).use(Uppy.Tus, {
                      endpoint: '/big/upload/'
                    })
                    uppy.on('complete', (result) => {
                     // console.log(result) console.log('Upload complete! We’ve uploaded these files:', result.successful)
                    })
                    uppy.setMeta({ auth_token: 'xx',callback_url:'http://127.0.0.1/callback' })//这里是传递上传的认证参数,callback_url参数中 id为文件的ID,info 文转的基本信息json
                  </script>
                </div>
              </body>
</html>

更多客户端请参考

results matching ""

    No results matching ""