我正在尝试使用Salesforce Apex中的驱动器API创建可恢复的上传会话。
根据文档,需要遵循的3个步骤是
但我无法从响应中检索位置标头。即使我尝试了邮递员休息客户端的请求,它也遇到了同样的问题。
代码:
String body='{ "name" : "'+ filename+'",'+'"parents": ["0B3fYScqCn4pyWGRZVUIwWnNIbDg"] }';
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://www.googleapis.com/drive/v3/files?uploadType=resumable');
req.setHeader('Authorization', 'Bearer ' +accessToken);
system.debug('###accessToken'+accessToken);
req.setHeader('Content-Type', 'application/json;charset=UTF-8');
req.setHeader('Content-length', String.valueOf(body.length()));
req.setHeader('X-Upload-Content-Type',fileType);
req.setHeader('X-Upload-Content-Length',String.valueOf(fileSize));
req.setBody(body);
req.setMethod('POST');
//req.setTimeout(60*1000);
HttpResponse resp = http.send(req);
system.debug('@@@fileSize'+fileSize);
system.debug('@@@@@@@---'+resp.getbody());
system.debug('@@@@@@@---'+resp.getHeader('Location')); //returning null
for(String str : resp.getHeaderKeys()){
system.debug('@@@@@@@---str:'+str+':: '+resp.getHeader(str));
//no header with location /Location
}
回应:
{
"kind": "drive#file",
"id": "0B3fYScqCn4pyaGRYN214MnpiV2s",
"name": "Untitled",
"mimeType": "application/octet-stream"
}
答案 0 :(得分:1)
您使用的是API的v2还是v3?您的端点是v2,您的问题是v3。 您是否使用正确的端点尝试了代码?
https://www.googleapis.com/upload/drive/v3/files