首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用节点js在协作白板中上传和查看.ppt或.pdf文件

使用节点js在协作白板中上传和查看.ppt或.pdf文件
EN

Stack Overflow用户
提问于 2015-09-24 18:10:50
回答 1查看 909关注 0票数 1

如何使用节点js在协作白板中上传和查看.ppt或.pdf文件。有人能告诉我应该使用哪种API吗?

EN

回答 1

Stack Overflow用户

发布于 2015-09-24 18:22:17

你应该使用强大的api上传和查看

Server.js

代码语言:javascript
复制
var formidable = require('formidable'),
http = require('http'),
util = require('util'),
fs = require('fs');
http.createServer(function(req, res) {
    if (req.url == '/view' && req.method == 'GET') {
        fs.readFile('./temp.pdf', function(err, file) {
            res.writeHead(200, {"Content-Type" : "application/pdf" });
            res.write(file, "binary");
            res.end();
        });
        return;
    }
    if (req.url == '/upload' && req.method == 'POST') {
        // parse a file upload
        var form = new formidable.IncomingForm();
        form.parse(req, function(err, fields, files) {
            fs.rename(files.upload.path, './temp.pdf');
            res.writeHead(200, {'content-type': 'text/html'});
            res.write('Received upload: <a href="/view">View PDF</a>');
            res.end();
        });
        return;
    }
    // show a file upload form
    res.writeHead(200, {'content-type': 'text/html'});
    res.end(
        '<form action="/upload" enctype="multipart/form-data" method="post">'+
        '<input type="file" name="upload" multiple="multiple"><br>'+
        '<input type="submit" value="Upload">'+
        '</form>'
    );
}).listen(80);

Formidable

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32758706

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档