OneDrive上传API,可恢复上传在网络上无效

时间:2015-07-08 06:46:22

标签: onedrive

我开发了网络应用。 http://onedrive.booogle.net/

  

OneDrive API的可恢复上传在网络上无效。简单   项目上传仅适用(100M限制)。 "请求标头字段   Access-Control-Allow-Headers不允许使用Content-Range。"

Chrome,Firefox上出现

错误... 它是错误的吗?如何解决?

function _upload_send(uploadUrl){
    var cfiledata='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    var body=btoa(cfiledata);
    var start=0;
    var end=cfiledata.length;
    var len=cfiledata.length;

    xhr.open('PUT', uploadUrl);
    xhr.setRequestHeader('Authorization', 'Bearer ' + md_access_token);
    xhr.setRequestHeader('Content-Range', 'bytes '+start+'-'+(end-1)+'/'+len);
    xhr.setRequestHeader('Content-Encoding', 'base64');     
    xhr.onload = function(){
        //Request header field Content-Range is not allowed by Access-Control-Allow-Headers.
    };
    xhr.onerror = function(e){   
        //Request header field Content-Range is not allowed by Access-Control-Allow-Headers.
    };                  
    xhr.send(body);     
}
function _upload_create(){
    filename='largefile.txt';
    xhr.open('POST', 'https://api.onedrive.com/v1.0'+'/drive/items/'+upload_id+':/'+encodeURIComponent(filename)+':/upload.createSession');
    xhr.setRequestHeader('Authorization', 'Bearer ' + md_access_token);
    xhr.setRequestHeader('Content-Type', 'application/json');
    var body={
      "item": {
        "@name.conflictBehavior": "rename",
        "name": filename
        }
    };
    xhr.onload = function(){
        if(this.status==200){
            try{
                var a=JSON.parse(this.response);
                if(a.uploadUrl){
                    _upload_send(a.uploadUrl);
                }
            }catch(err){}
        }
    };
    xhr.onerror = function(e){   
    };
    xhr.send(JSON.stringify(body));     
}

1 个答案:

答案 0 :(得分:0)

这是一个错误。谢谢你报道。使用https://github.com/OneDrive/onedrive-api-docs/issues/157进行跟踪。我们很快就会解决它。

- 更新 -

现在已修复。