I'm uploading files to a GCS bucket with the JSON API and the upload is resumable. I'm doing this from the browser using JS.
The files upload with no problems. If there is a network problem then I try to resume it. Per the documentation I'm sending an empty PUT request to the upload URI. Then parsing the range
header of the response. But then I get the error:
Refused to get unsafe header "range"
This is the code:
var xhr = new XMLHttpRequest();
xhr.open("PUT", url, true);
xhr.setRequestHeader("Authorization", token);
xhr.setRequestHeader("content-range", "bytes */" + file_object.size);
xhr.onreadystatechange = function () {
if (xhr.readyState != 4) {
return;
}
if (xhr.status === 308) {
var range = xhr.getResponseHeader("range"); // Error here
// continue with the upload
}
};
xhr.send();
I'm creating the upload URI at the server side with Python. These are the headers included in the request:
headers = {
"Authorization": authorization,
"Content-Type": "application/json; charset=UTF-8",
"origin": 'http://' + self.request.headers.get('HOST'),
"X-Upload-Content-Type": content_type,
"X-Upload-Content-Length": content_length,
}
How can I read the header range
?