尝试使用Base64上传图像,但如果字符串很长,则存储图像的底部为空白。
var uuid = require('node-uuid');
var fs = require('fs');
exports.uploadImage = function(base64Str, callback) {
var filename = uuid.v1()+'.png';
var bitmap = new Buffer(base64Str, 'base64');
fs.writeFileSync(filename, bitmap);
callback(filename);
};
var fs = require('fs');
var restify = require('restify');
var server = restify.createServer();
server.use(restify.bodyParser());
var upload = require('./modules/upload');
server.post('/images', function(req, res) {
upload.uploadImage(req.params.myImage, function(filename) {
console.log('processing image');
res.send(filename);
res.end();
});
});
server.listen(3000);
它适用于长度为499016字节的字符串,但如果字符串为847508字节则不起作用。是否有文档大小限制,如果没有,我如何上传和取消编码更长的字符串?