0

次のコードがあります。

Meteor.methods({
  saveFile: function(blob, name, path, encoding) {
    var path = cleanPath(path), fs = __meteor_bootstrap__.require('fs'),
      name = cleanName(name || 'file'), encoding = encoding || 'binary',
      chroot = Meteor.chroot || 'public';
    // Clean up the path. Remove any initial and final '/' -we prefix them-,
    // any sort of attempt to go to the parent directory '..' and any empty directories in
    // between '/////' - which may happen after removing '..'
    path = chroot + (path ? '/' + path + '/' : '/');

    // TODO Add file existance checks, etc...
    fs.writeFile(path + name, blob, encoding, function(err) {
      if (err) {
        throw (new Meteor.Error(500, 'Failed to save file.', err));
      } else {
        console.log('The file ' + name + ' (' + encoding + ') was saved to ' + path);
      }
    }); 

    function cleanPath(str) {
      if (str) {
        return str.replace(/\.\./g,'').replace(/\/+/g,'').
          replace(/^\/+/,'').replace(/\/+$/,'');
      }
    }
    function cleanName(str) {
      return str.replace(/\.\./g,'').replace(/\//g,'');
    }
  }
});

このプロジェクトから取ったもの https://gist.github.com/dariocravero/3922137

コードは正常に動作し、ファイルを保存しますが、呼び出しを数回繰り返し、そのたびに Windows バージョン 0.5.4 を使用して meteor をリセットします。F12 コンソールは最終的に次のようになりますここに画像の説明を入力。meteor コンソールは、503 が発生するたびに起動コードをループし、saveFile 関数でコンソール ログを繰り返します。

さらに、ターゲットディレクトリでは、画像のサムネイルが表示され続け、壊れたものとして表示され、有効なサムネイルが再び表示されfsます。

関数を呼び出すコードは次のとおりです。

"click .savePhoto":function(e, template){
    e.preventDefault();
     var MAX_WIDTH = 400;
    var MAX_HEIGHT = 300;
    var id = e.srcElement.id;
    var item = Session.get("employeeItem");
    var file = template.find('input[name='+id+']').files[0];
  // $(template).append("Loading...");
  var dataURL = '/.bgimages/'+file.name;
    Meteor.saveFile(file, file.name, "/.bgimages/", function(){
        if(id=="goodPhoto"){
            EmployeeCollection.update(item._id, { $set: { good_photo: dataURL }});
        }else{
            EmployeeCollection.update(item._id, { $set: { bad_photo: dataURL }});
        }
        // Update an image on the page with the data
        $(template.find('img.'+id)).delay(1000).attr('src', dataURL);
    });     



},

サーバーがリセットされる原因は何ですか?

4

1 に答える 1