【问题标题】:Is it possible to upload PPT to Google drive and download as images in NODEJS是否可以将 PPT 上传到 Google 驱动器并在 NODEJS 中作为图像下载
【发布时间】:2015-03-04 10:19:22
【问题描述】:

您好,我已经开始使用 googleapis npm 并且可以列出和创建文档等。是否可以上传 powerpoint 文档并将其保存在 google 驱动器中,当我想下载它时,它会作为单独的图像下载。我已经看到 Aspose.Slides 可以做到,但是我希望能够使用 google docs。

任何帮助都会很棒

到目前为止我的代码是

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

我已将其从服务器端身份验证更改为服务器端 oauth。我可以上传一个ppt并在google docs中打开它,我只需要知道如何能够将ppt作为单独的图像下载

【问题讨论】:

  • 嗨瑞克,你试过什么?
  • 到目前为止,我已将代码添加到问题中
  • 经过进一步研究,我改变了认证方式,现在可以上传,只需要将PPT转换成图片

标签: javascript node.js google-api


【解决方案1】:

经过大量研究,目前还无法完成

【讨论】:

    猜你喜欢
    • 2020-08-10
    • 1970-01-01
    • 2014-05-26
    • 2019-01-23
    • 1970-01-01
    • 1970-01-01
    • 2021-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多