首页 文章

通过Node.js将.tif上传到GeoServer

提问于
浏览
-1

如何通过Node.js将.tif文件上传到我正在运行的GeoServer?我想通过GeoServer上传一个GeoTIFF作为WMS .

GeoServer正在响应405,我认为是正确的(http://docs.geoserver.org/latest/en/user/rest/api/coveragestores.html#workspaces-ws-coveragestores-cs-file-extension) . 不幸的是,我在GeoServer上找不到该文件 .

这是我的代码:

// GeoServer upload

var http = require('http'); 
var auth = 'Basic ' + new Buffer('admin' + ':' + 'geoserver').toString('base64');
//build the object to post
var post_data = (path.join(paperpath, paperid, "geotiff", req.files["otherfiles"][fileno].originalname)); // Path to .tif file

var s = JSON.stringify(post_data);
var post_options = {
  host: 'localhost',
  port: '9000',
  path: '/geoserver/rest/workspaces/myWorkspace/coveragestores/test/file',
  method: 'POST',
  headers: {
    'Content-Length': s.length,
    'Content-Type': 'image/tif',
    'Authorization': auth
  }
}
  // Set up the request
var post_req = http.request(post_options, function(res) {
  res.setEncoding('utf8');
  console.log(res.statusCode);

  res.on('data', function(chunk) {
    console.log('Success! ' + chunk);
  });
});
// post the data
post_req.write(s);
post_req.end();

1 回答

  • 0

    我想首先你需要在一个可以从geoserver访问的文件夹中上传文件(更好地在geoserver数据目录的文件夹中),然后使用其余的api来配置coverage存储 . 检查这个blog post它应该给你一个提升

相关问题