先将文件名称和文件大小等信息传给后台获取文件上传链接,上传文件时,当content-type为application/octet-stream
时,表示只能上传一个文件
js
const fetch = require('node-fetch');
const fs = require('fs');
const stream = fs.createReadStream('./test.mp4');
fetch(url, {
method: 'PUT',
headers: {
'Content-Type': 'application/octet-stream',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
'Connection': 'keep-alive',
'Content-Length': size // 文件大小 必须 它决定了文件大小 请求返回时间 否则文件缺失
},
body: stream
})
.then(res => {
console.log('上传完成了')
})