2017-05-03 111 views
0

我使用'express'模塊上傳文件。我必須使用node-exif來讀取上傳圖像的EXIF數據。我不想將文件存儲在磁盤上,上述模塊支持從緩衝區讀取EXIF數據。我需要從上傳的圖像中讀取緩衝區數據。這裏是上傳代碼:從NodeJS上傳文件中讀取緩衝區數據

var express = require('express'); 
var app = express(); 
var fs = require('fs'); 
var multiparty = require("multiparty"); 

module.exports.UploadImage = function (req, res, next) { 
    // Handle request as multipart 
    if (!req.files) 
     return res.status(400).send('No files were uploaded.'); 

    var sampleFile = req.files.uploadedFile; 
    //Here I need to have the buffer. 
    res.send('Done!'); 
} 

有人可以幫助我獲取緩衝區數據,因爲我是非常新的節點宇宙?

回答

0

我認爲這是你在找什麼

module.exports.UploadImage = function (req, res, next) { 
    // Handle request as multipart 
    if (!req.files) 
     return res.status(400).send('No files were uploaded.'); 

    var sampleFile = req.files.uploadedFile; 
    //Here I need to have the buffer. 
    var chunks = [] 
    req.on('data', function (chunk) { 
     // reads chunks of data in Buffer 
     console.log(chunk) // Prints <Buffer 8a 83 ef ... > 
     chunks.push(chunk) 
    }) 

    res.send('Done!'); 
    }