我正在尝试使用tus library here上传到vimeo平台。以下是我如何启动此上传过程的代码段:
private void parseJSON() {
String url = "https://example.com/index.json";
JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, url, null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try {
for (int i = 0; i < response.length(); i++) {
JSONObject object = response.getJSONObject(i);
String title = object.getString("subject");
String description = object.getString("message");
String imageUrl = object.getString("thumb");
Integer threadId = object.getInt("threadId");
mList.add(new Item( title, description, threadId));
}
mItemAdapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
然后,当启动了新的tus上传时,它将调用Tus库中的Upload方法,该方法具有http变量,如下所示:
document.getElementById('browse').addEventListener("input", function(e) {
// Get the selected file from the input element
var file = e.target.files[0]
var myToken = document.getElementById('accessToken')
var url = 'https://api.vimeo.com/me/videos'
var xhr = new XMLHttpRequest()
xhr.open('POST', 'https://api.vimeo.com/me/videos', true)
xhr.setRequestHeader('Authorization', 'Bearer ' + myToken.value)
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.setRequestHeader('Accept', 'application/vnd.vimeo.*+json;version=3.4')
xhr.onload = function(e) {
if (e.target.status < 400) {
console.log(e.target.status) //this returns status 200
var response = JSON.parse(e.target.responseText)
// Create a new tus upload
var upload = new tus.Upload(file, {
endpoint: response.upload.upload_link, //this looks like vimeo.api.tus... something like that
retryDelays: [0, 1000, 3000, 5000],
metadata: {
filename: file.name,
filetype: file.type
},
onError: function(error) {
console.log("Failed because: " + error)
},
onProgress: function(bytesUploaded, bytesTotal) {
var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2)
console.log(bytesUploaded, bytesTotal, percentage + "%")
},
onSuccess: function() {
console.log("Download %s from %s", upload.file.name, upload.url)
}
})
// Start the upload
upload.start()
} else {
console.log("This is a developer error: " + e)
console.log(e.target.status)
}
}.bind(this)
xhr.send(JSON.stringify({
upload:{
approach: 'tus',
size: file.size
}
}));
})
现在的问题是此过程向我返回了以下错误:
失败,因为:错误:tus:无效或缺少位置标题, 源自请求(响应代码:204,响应文本:)
从我的角度来看,该位置标头应该在所发出请求的响应中。我该如何解决??