Skip to content

Instantly share code, notes, and snippets.

@alexbosworth
Created May 8, 2012 03:12
Show Gist options
  • Save alexbosworth/2632269 to your computer and use it in GitHub Desktop.
Save alexbosworth/2632269 to your computer and use it in GitHub Desktop.
gdrive
var request = require('request'),
ENDPOINT = 'https://www.googleapis.com/';
exports.save = function(opt, cbk) {
var auth = 'Bearer ' + opt.access_token;
opt.mimeType = opt.mimeType || 'application/octet-stream';
request.post({
url: ENDPOINT + 'drive/v1/files/',
headers: { Authorization: auth },
json: {
title: opt.title,
mimeType: opt.mimeType,
description: opt.description,
}
},
function(err, r, file) {
request.put({
url: ENDPOINT + 'upload/drive/v1/files/' + file.id,
headers: {
Authorization: auth,
'Content-Type': opt.mimeType
},
body: opt.file
},
function(err, r, responseBody) {
return cbk(err);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment