2012-03-21 4 views
0

노드 및 Google 문서 도구 REST API를 사용하여 파일을 업로드하려고합니다. 메타 데이터를 포함하지 않으면 파일을 잘 업로드 할 수 있지만 항상 '제목 없음'으로 업로드됩니다. 나는 내 원자 데이터를 전송 및 파일 업로드를 계속 시도 후 다음과 같은 오류 얻을 메타 데이터를 포함 할 때Google 문서 도구 API : 문서 제목을 설정할 수 없습니다.

그러나 :

는 ParseException을 - 내용이 내 첫 번째 프롤로그

에서 허용되지 않습니다 재개 가능한 미디어 링크를 업로드 세션을 생성하고 얻을 요청

var meta = '<?xml version="1.0" encoding="UTF-8"?>' 
    meta+= '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:docs="http://schemas.google.com/docs/2007">' 
    meta+= '<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/docs/2007#document"/>' 
    meta+= '<title>Test</title></entry>' 

var options = { 
    host: 'docs.google.com', 
    path: '/feeds/upload/create-session/default/private/full', 
    method: 'POST', 
    headers: { 
     'Host' : 'docs.google.com', 
     'Content-Length' : meta.length, 
     'Content-Type': 'application/atom+xml', 
     'GData-Version' : 3, 
     'Authorization' : 'GoogleLogin auth=' + authToken, 
     'X-Upload-Content-Type' : 'application/msword', 
     'X-Upload-Content-Length' : 31232 
    } 
} 

var req = https.request(options, function (res) { 
    // make 2nd request 

}); 

req.end(meta); 

이 제 2 요청이 재개 미디어 링크

을받은 후 모습입니다
var options = { 
    host: 'docs.google.com', 
    path: resumableMediaLink, 
    method: 'PUT', 
    headers: { 
     'Content-Length': data.length, 
     'Content-Type': 'application/msword', 
     'Content-Range': 'bytes 0-' + (data.length-1) +'/'+ data.length 
    } 
} 

var req = https.request(options, function (res) { 
    res.on('data', function (chunk) { 
     // ... 
    }); 
}); 

req.write(data); 
req.end(); 

원자 데이터를 잘못 보내고있는 것처럼 보입니다. 내가 뭘 잘못했는지 생각해?

답변

0

내가 잘못한 것을 알았습니다.

재개 가능한 세션을 시작하려면 첫 번째 POST 요청에 '슬러그'헤더를 설정해야했습니다.

다음 요청에서 받았습니다.

관련 문제