nodejs - Express request shape zip from geoserver return 文本
nodejs - Express request shape zip from geoserver return text
我正在向 express (node.js) 请求地理服务器以在 wfs 服务中获取形状 zip,但我只收到文本。
var express = require('express');
var router = express.Router();
var fs = require('fs');
var request = require("request");
var DOWNLOAD_DIR = './downloads/';
router.get('/', function(req, res, next) {
var file_url='https://geo.gob.bo/geoserver/aasana/wfs?SERVICE=WFS&VERSION=1.1.0&REQUEST=GetFeature&typeName=aerodromos&outputFormat=shape-zip';
request(file_url, function(err, resp, body) {
console.log('res',res);
console.log('body',body);
if(!err){
var file = fs.createWriteStream(DOWNLOAD_DIR + 'aerodromos');
var buff = new Buffer(body);
file.write(buff,function(err){
console.log(err);
});
file.end();
console.log(' downloaded to ' + DOWNLOAD_DIR);
}else{
console.log("No results error.",err);
}
});
res.render('index', { title: 'descargado' });
});
module.exports = router;
我正在尝试将其放入一个 zip 文件中,但我无法打开它。
您需要将编码设置为 null,在您的情况下它将被视为缓冲区而不是字符串
request({url: file_url, encoding: null}, function(err, resp, body) {
我正在向 express (node.js) 请求地理服务器以在 wfs 服务中获取形状 zip,但我只收到文本。
var express = require('express');
var router = express.Router();
var fs = require('fs');
var request = require("request");
var DOWNLOAD_DIR = './downloads/';
router.get('/', function(req, res, next) {
var file_url='https://geo.gob.bo/geoserver/aasana/wfs?SERVICE=WFS&VERSION=1.1.0&REQUEST=GetFeature&typeName=aerodromos&outputFormat=shape-zip';
request(file_url, function(err, resp, body) {
console.log('res',res);
console.log('body',body);
if(!err){
var file = fs.createWriteStream(DOWNLOAD_DIR + 'aerodromos');
var buff = new Buffer(body);
file.write(buff,function(err){
console.log(err);
});
file.end();
console.log(' downloaded to ' + DOWNLOAD_DIR);
}else{
console.log("No results error.",err);
}
});
res.render('index', { title: 'descargado' });
});
module.exports = router;
我正在尝试将其放入一个 zip 文件中,但我无法打开它。
您需要将编码设置为 null,在您的情况下它将被视为缓冲区而不是字符串
request({url: file_url, encoding: null}, function(err, resp, body) {