![](/img/trans.png)
[英]Download file from Google Drive and upload to S3 using NodeJS
[英]Is it possible to upload PPT to Google drive and download as images in NODEJS
嗨我已經開始使用googleapis npm並且可以列出並創建文檔等。是否可以上傳一個powerpoint doc將它保存在谷歌驅動器中,當我想下載它時,它可以作為單獨的圖像下載。 我已經看到Aspose.Slides可能會這樣做,但我希望能夠使用谷歌文檔。
任何幫助都會很棒
到目前為止我的代碼是
var express = require('express')
, request = require('request')
, oauth = require('./oauth')
, app = express();
// Setup middleware
app.use(express.static(__dirname));
// List out file that are in your Google Drive
app.get('/upload', function(req, res) {
// Check to see if user has an access_token first
var fs = require('fs');
var ENDPOINT_OF_GDRIVE = 'https://www.googleapis.com/drive/v2';
var PARENT_FOLDER_ID = 'XXXXXXX';
var PNG_FILE = 'test.ppt';
if (oauth.access_token) {
var accessToken = oauth.access_token;
var fstatus = fs.statSync(PNG_FILE);
fs.open(PNG_FILE, 'r', function(status, fileDescripter) {
if (status) {
console.log(status.message);
//return;
}
var buffer = new Buffer(fstatus.size);
fs.read(fileDescripter, buffer, 0, fstatus.size, 0, function(err, num) {
request.post({
'url': 'https://www.googleapis.com/upload/drive/v2/files',
'qs': {
//request module adds "boundary" and "Content-Length" automatically.
'uploadType': 'multipart'
},
'headers' : {
'Authorization': 'Bearer ' + accessToken
},
'multipart': [
{
'Content-Type': 'application/json; charset=UTF-8',
'body': JSON.stringify({
'title': PNG_FILE,
'parents': [
{
'id': PARENT_FOLDER_ID
}
]
})
},
{
'Content-Type': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'body': buffer
}
]
}, function(error, response, body){
console.log(error);
console.log(response);
console.log(body);
});
});
});
} else {
console.log("2nd Could not determine if user was authed. Redirecting to /");
res.redirect('/');
}
});
// Handle OAuth Routes
app.get('/login', oauth.login);
app.get('/auth/google/callback', oauth.callback);
app.get('/callback', oauth.callback);
app.listen(3000);
我已將其從服務器端auth更改為服務器端oauth。 我可以上傳一個ppt並在谷歌文檔中打開它,我只需要知道如何能夠下載ppt作為單獨的圖像
經過大量的研究,它還沒有完成
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.