我正在尝试使用Vanilla js上传视频,但是我无法使其正常运行。
我尝试使用FormData()函数,但是由于响应中出现以下错误,因此无法正常工作:index.js:46 Uncaught (in promise) SyntaxError: Unexpected end of JSON input
。虽然我确实收到了204状态代码。
我也尝试过删除Content-Type
标头,但是如果这样做,我会得到400状态代码。
const formData = new FormData()
formData.append("untitled","./video.mp4")
const UploadVideo = (() => {
const size = 10498677
return fetch('https://api.vimeo.com/me/videos', {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer 0541d1a97b7ed729ac8fcaf909b7e9f1",
"Accept": "application/vnd.vimeo.*+json;version=3.4"
},
body: JSON.stringify({
"upload": {
"approach": "tus",
"size": size
}
})
})
.then(response => response.json())
.then(response => {
const url= response.upload.upload_link
PatchUpload(url,size,0)
})
})();
const PatchUpload = (url, size, offset) => {
return fetch(url, {
method: "PATCH",
headers: {
"Tus-Resumable": "1.0.0",
"Upload-Offset": offset,
"Content-Type": "application/offset+octet-stream",
"Accept": "application/vnd.vimeo.*+json;version=3.4"
},
body: formData
})
.then(response=>response.json())
.then(response=>{
console.log(response)
})
}
关于如何将二进制文件传递给vimeo的任何提示?