简体   繁体   English

是否可以将PPT上传到Google驱动器并在NODEJS中作为图像下载

[英]Is it possible to upload PPT to Google drive and download as images in NODEJS

Hi I have started using googleapis npm and can list and create a documents etc. Is it possible to upload a powerpoint doc have it saved in google drive and when I want to download it, it be downloaded as separate images. 嗨我已经开始使用googleapis npm并且可以列出并创建文档等。是否可以上传一个powerpoint doc将它保存在谷歌驱动器中,当我想下载它时,它可以作为单独的图像下载。 I have seen that Aspose.Slides may do it however i was hoping to be able to use google docs. 我已经看到Aspose.Slides可能会这样做,但我希望能够使用谷歌文档。

Any assistance would be awesome 任何帮助都会很棒

My code so far is 到目前为止我的代码是

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);

I have changed it from server side auth to server side oauth. 我已将其从服务器端auth更改为服务器端oauth。 I can upload a ppt and open it fine in google docs, I just need to know how to be able to download the ppt as separate images 我可以上传一个ppt并在谷歌文档中打开它,我只需要知道如何能够下载ppt作为单独的图像

经过大量的研究,它还没有完成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM