在Node.js中转换为Tiff到png失败

时间:2018-11-02 22:24:05

标签: node.js angular npm mean-stack

我是MEAN Stack的新手,我正在使用MEAN Stack和Angular 6实现一个Web应用程序。在这里,我想选择一个文件扩展名为'.tiff'的地图。我想将其转换为“ .png”格式,然后将“ .png”文件上传到名为“ uploads”的单独文件夹中。这是我的路线。 我在c目录中创建了一个名为“ mapImages”的文件夹,以保存tiff文件。然后我在c目录中创建了“ mapImages1”文件夹,以保留转换后的图像。但是当我上传时,它会出现以下错误。

aa(已创建)     ✗转换失败   0已转换。   1失败。 C:mapImages1 / aa 错误:命令失败:转换C:mapImages \ aa.tif C:mapImages1 / aa /%d.png 参数无效-C:mapImages1

var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var multer = require('multer');
var ConvertTiff = require('tiff-to-png');

var mapInfo = require('../../../models/mongoModels/map');

var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'uploads/')
  },
  filename: function (req, file, cb) {
    cb(null, file.fieldname + '-' + Date.now() + '.png')
  }
})

var upload = multer({ storage: storage });
router.post('/uploadMap', upload.single('milespecMap'), function (req, res, next) {
  var imageName = req.file.filename;
  var options = {
    logLevel: 1
  };
  var converter = new ConvertTiff(options);
  var location = '';
  converter.convertOne(req.file.originalname+'.tif', location);
  res.send(imageName);

});


//Save or update map 

router.post("/update", function (req, res) {
      var mod = new mapInfo(req.body);
      mapInfo.findOneAndUpdate(
        {
          mapName: req.body.mapName,
        },
        req.body,
        { upsert: true, new: true },

        function (err, data) {
          if (err) {
            console.log(err);
            res.send(err);
          } else {
            // console.log(res);
            res.send(mod);
          }
        }
      );
    });

  module.exports = router;

这是我的.ts文件

export class MapsComponent implements OnInit {
  closeResult: string;
  currentMapDetails: Map = new Map();
  selectedFile: File = null;
  imageName: string;

  public uploader: FileUploader = new FileUploader({ url: URL, itemAlias: 'milespecMap', });
  private items: any;
  constructor(private modalService: NgbModal,
    private mapsService: MapsService,
    private http: Http,
    private router: Router,

  ) {
    this.uploader.onAfterAddingAll(this.items)
    {
      console.log(this.items);
    }

    this.uploader.onCompleteItem = (item: any, response: any, status: any, headers: any) => {
      //things to do on completion
      this.imageName= response;
      console.log("image"+ " "+response);
    };

  }

  ngOnInit() {
  }

  handleFileInput(file: FileList) {
    this.selectedFile = file.item(0);
    var reader = new FileReader();
    reader.onload = (event: any) => {
      this.currentMapDetails.milespecUrl = event.target.result;
      console.log(reader.onload);
    }
    reader.readAsDataURL(this.selectedFile);

  }

  updateInfo() {
    this.uploader.uploadAll(); ///image upload
    this.update();
  }

  update() {
    console.log(this.currentMapDetails);
    this.mapsService.updateMap(this.currentMapDetails).subscribe(res => {
      this.currentMapDetails;
      console.log(res);
    }, (err) => {
      console.log(err);
    });
  }
}

在multer对象中,我已经得到了扩展名为'.png'的文件。我不知道它是否影响此错误。我为此付出了很多努力。谁能给我建议解决这个问题?

0 个答案:

没有答案