2017-09-15 14 views
-1

問題が多発した後、ファイルのアップロードでファイルアップロードをchangeイベントに移動することを決定しました。入力変更イベントでCollectionFSを挿入すると、リフレッシュとエラーが発生する

HTML:

<form class="form-inline" id="cost-estimate-form"> 
     <div class="form-field-short col s12 m6"> 
      <i class="material-icons prefix">insert_photo</i> 
      <label for="input-file">Upload photos</label> 
      <input id="input-file" type="file" name="images" accept="image/jpeg, image/png, application/pdf" multiple/> <!-- todo: ugly on safari --> 
     </div> 
     <!-- Rest of code --> 

の.js:

'change #input-file': function(event, template) { 
    uploadedImageFiles = []; 
    FS.Utility.eachFile(event, function(file) { 
     Image.insert(file, function (err, fileObj) { 
      //If !err, we have inserted new doc with ID fileObj._id, and 
      //kicked off the data upload using HTTP 
     }); 
    }); 
}, 

、私はブラウザに入力するための3つのファイルを選択するたびに、私は、ブラウザのコンソールログにこのエラーが表示されます。

cfs_power-queue.js:525 Error: "Queue" network [undefined], Error 
    at cfs_upload-http.js:382 
    at cfs_upload-http.js:108 
    at underscore.js:794 
    at XMLHttpRequest.xhr.onreadystatechange (cfs_upload-http.js:167) 
PowerQueue.runTaskDone @ cfs_power-queue.js:525 
taskCallbackDone @ cfs_power-queue.js:607 
(anonymous) @ cfs_upload-http.js:382 
(anonymous) @ cfs_upload-http.js:108 
(anonymous) @ underscore.js:794 
xhr.onreadystatechange @ cfs_upload-http.js:167 
XMLHttpRequest.send (async) 
httpCall @ cfs_upload-http.js:237 
gotBinaryCallback @ cfs_upload-http.js:373 
reader.onload @ cfs_data-man.js:336 
FileReader (async) 
read @ cfs_data-man.js:341 
(anonymous) @ cfs_data-man.js:363 
dataManGetBlob @ cfs_data-man.js:289 
dataManGetBinary @ cfs_data-man.js:344 
_taskHandler @ cfs_upload-http.js:366 
PowerQueue.runTask @ cfs_power-queue.js:606 
PowerQueue.updateThrottleUp @ cfs_power-queue.js:412 
PowerQueue.next @ cfs_power-queue.js:461 
(anonymous) @ cfs_power-queue.js:575 
withValue @ meteor.js:1077 
(anonymous) @ meteor.js:464 
(anonymous) @ meteor.js:1105 
setTimeout (async) 
setTimeout @ meteor.js:487 
PowerQueue.runTaskDone @ cfs_power-queue.js:574 
taskCallbackDone @ cfs_power-queue.js:607 
(anonymous) @ cfs_upload-http.js:384 
(anonymous) @ cfs_upload-http.js:108 
(anonymous) @ underscore.js:794 
xhr.onreadystatechange @ cfs_upload-http.js:231 
XMLHttpRequest.send (async) 
httpCall @ cfs_upload-http.js:237 
gotBinaryCallback @ cfs_upload-http.js:373 
reader.onload @ cfs_data-man.js:336 
FileReader (async) 
read @ cfs_data-man.js:341 
(anonymous) @ cfs_data-man.js:363 
dataManGetBlob @ cfs_data-man.js:289 
dataManGetBinary @ cfs_data-man.js:344 
_taskHandler @ cfs_upload-http.js:366 
PowerQueue.runTask @ cfs_power-queue.js:606 
PowerQueue.updateThrottleUp @ cfs_power-queue.js:412 
PowerQueue.next @ cfs_power-queue.js:461 
PowerQueue.run @ cfs_power-queue.js:750 
PowerQueue.queueTaskHandler @ cfs_power-queue.js:638 
PowerQueue.runTask @ cfs_power-queue.js:597 
PowerQueue.updateThrottleUp @ cfs_power-queue.js:412 
PowerQueue.next @ cfs_power-queue.js:461 
(anonymous) @ cfs_power-queue.js:575 
withValue @ meteor.js:1077 
(anonymous) @ meteor.js:464 
(anonymous) @ meteor.js:1105 
setTimeout (async) 
setTimeout @ meteor.js:487 
PowerQueue.runTaskDone @ cfs_power-queue.js:574 
subQueueCallbackDone @ cfs_power-queue.js:598 
subQueue.onRelease @ cfs_power-queue.js:631 
PowerQueue.next @ cfs_power-queue.js:474 
(anonymous) @ cfs_power-queue.js:575 
withValue @ meteor.js:1077 
(anonymous) @ meteor.js:464 
(anonymous) @ meteor.js:1105 
setTimeout (async) 
setTimeout @ meteor.js:487 
PowerQueue.runTaskDone @ cfs_power-queue.js:574 
taskCallbackDone @ cfs_power-queue.js:607 
(anonymous) @ cfs_upload-http.js:384 
(anonymous) @ cfs_upload-http.js:108 
(anonymous) @ underscore.js:794 
xhr.onreadystatechange @ cfs_upload-http.js:231 
XMLHttpRequest.send (async) 
httpCall @ cfs_upload-http.js:237 
gotBinaryCallback @ cfs_upload-http.js:373 
reader.onload @ cfs_data-man.js:336 
FileReader (async) 
read @ cfs_data-man.js:341 
(anonymous) @ cfs_data-man.js:363 
dataManGetBlob @ cfs_data-man.js:289 
dataManGetBinary @ cfs_data-man.js:344 
_taskHandler @ cfs_upload-http.js:366 
PowerQueue.runTask @ cfs_power-queue.js:606 
PowerQueue.updateThrottleUp @ cfs_power-queue.js:412 
PowerQueue.next @ cfs_power-queue.js:461 
(anonymous) @ cfs_power-queue.js:575 
withValue @ meteor.js:1077 
(anonymous) @ meteor.js:464 
(anonymous) @ meteor.js:1105 
setTimeout (async) 
setTimeout @ meteor.js:487 
PowerQueue.runTaskDone @ cfs_power-queue.js:574 
taskCallbackDone @ cfs_power-queue.js:607 
(anonymous) @ cfs_upload-http.js:384 
(anonymous) @ cfs_upload-http.js:108 
(anonymous) @ underscore.js:794 
xhr.onreadystatechange @ cfs_upload-http.js:231 
XMLHttpRequest.send (async) 
httpCall @ cfs_upload-http.js:237 
gotBinaryCallback @ cfs_upload-http.js:373 
reader.onload @ cfs_data-man.js:336 
FileReader (async) 
read @ cfs_data-man.js:341 
(anonymous) @ cfs_data-man.js:363 
dataManGetBlob @ cfs_data-man.js:289 
dataManGetBinary @ cfs_data-man.js:344 
_taskHandler @ cfs_upload-http.js:366 
PowerQueue.runTask @ cfs_power-queue.js:606 
PowerQueue.updateThrottleUp @ cfs_power-queue.js:412 
PowerQueue.next @ cfs_power-queue.js:461 
(anonymous) @ cfs_power-queue.js:575 
withValue @ meteor.js:1077 
(anonymous) @ meteor.js:464 
(anonymous) @ meteor.js:1105 
setTimeout (async) 
setTimeout @ meteor.js:487 
PowerQueue.runTaskDone @ cfs_power-queue.js:574 
taskCallbackDone @ cfs_power-queue.js:607 
(anonymous) @ cfs_upload-http.js:384 
(anonymous) @ cfs_upload-http.js:108 
(anonymous) @ underscore.js:794 
xhr.onreadystatechange @ cfs_upload-http.js:231 
XMLHttpRequest.send (async) 
httpCall @ cfs_upload-http.js:237 
gotBinaryCallback @ cfs_upload-http.js:373 
reader.onload @ cfs_data-man.js:336 
FileReader (async) 
read @ cfs_data-man.js:341 
(anonymous) @ cfs_data-man.js:363 
dataManGetBlob @ cfs_data-man.js:289 
dataManGetBinary @ cfs_data-man.js:344 
_taskHandler @ cfs_upload-http.js:366 
PowerQueue.runTask @ cfs_power-queue.js:606 
PowerQueue.updateThrottleUp @ cfs_power-queue.js:412 
PowerQueue.next @ cfs_power-queue.js:461 
PowerQueue.run @ cfs_power-queue.js:750 
PowerQueue.queueTaskHandler @ cfs_power-queue.js:638 
PowerQueue.runTask @ cfs_power-queue.js:597 
PowerQueue.updateThrottleUp @ cfs_power-queue.js:412 
PowerQueue.next @ cfs_power-queue.js:461 
PowerQueue._autoStartTasks @ cfs_power-queue.js:366 
PowerQueue.add @ cfs_power-queue.js:391 
UploadTransferQueue.self.uploadFile @ cfs_upload-http.js:578 
beginStorage @ cfs_collection.js:246 
(anonymous) @ cfs_collection.js:282 
(anonymous) @ mongo.js:720 
(anonymous) @ meteor.js:1105 
_maybeInvokeCallback @ ddp-client.js:3679 
dataVisible @ ddp-client.js:3709 
(anonymous) @ ddp-client.js:4560 
_.each._.forEach @ underscore.js:149 
_runAfterUpdateCallbacks @ ddp-client.js:4559 
_performWrites @ ddp-client.js:4549 
_flushBufferedWrites @ ddp-client.js:4512 
_livedata_data @ ddp-client.js:4478 
onMessage @ ddp-client.js:3526 
(anonymous) @ ddp-client.js:2909 
_.each._.forEach @ underscore.js:149 
self.socket.onmessage @ ddp-client.js:2908 
REventTarget.dispatchEvent @ ddp-client.js:143 
SockJS._dispatchMessage @ ddp-client.js:1310 
SockJS._didMessage @ ddp-client.js:1376 
that.ws.onmessage @ ddp-client.js:1532 

(2) Navigated to http://localhost:3000/travel/travel_requests/new 

エラーです。次に、ページ(ナビゲーション)を2回リフレッシュします。

入力が明らかに選択を失います。

そして、私はデシベルでdb.cfs.images.filerecord.find({}).pretty()を実行する場合、私はこれを取得:

{ 
    "_id" : "rEeTyZNiXKokabskw", 
    "original" : { 
     "name" : "IMG_3867.JPG", 
     "updatedAt" : ISODate("2017-07-19T02:57:55Z"), 
     "size" : 4231984, 
     "type" : "image/jpeg" 
    }, 
    "uploadedAt" : ISODate("2017-09-15T07:31:44.011Z"), 
    "copies" : { 
     "images" : { 
      "name" : "IMG_3867.JPG", 
      "type" : "image/jpeg", 
      "size" : 4231984, 
      "key" : "images-rEeTyZNiXKokabskw-IMG_3867.JPG", 
      "updatedAt" : ISODate("2017-09-15T07:31:44Z"), 
      "createdAt" : ISODate("2017-09-15T07:31:44Z") 
     } 
    } 
} 
{ 
    "_id" : "csmJXhToHqpQ3PTo3", 
    "original" : { 
     "name" : "IMG_3868.JPG", 
     "updatedAt" : ISODate("2017-07-19T02:58:07Z"), 
     "size" : 4103858, 
     "type" : "image/jpeg" 
    }, 
    "uploadedAt" : ISODate("2017-09-15T07:31:46.481Z"), 
    "copies" : { 
     "images" : { 
      "name" : "IMG_3868.JPG", 
      "type" : "image/jpeg", 
      "size" : 4103858, 
      "key" : "images-csmJXhToHqpQ3PTo3-IMG_3868.JPG", 
      "updatedAt" : ISODate("2017-09-15T07:31:46Z"), 
      "createdAt" : ISODate("2017-09-15T07:31:46Z") 
     } 
    } 
} 
{ 
    "_id" : "zypefr68MXpeBp3uY", 
    "original" : { 
     "name" : "IMG_3869.JPG", 
     "updatedAt" : ISODate("2017-07-19T02:58:10Z"), 
     "size" : 4108047, 
     "type" : "image/jpeg" 
    }, 
    "chunkSize" : 2097152, 
    "chunkCount" : 0, 
    "chunkSum" : 2 
} 

ので、二つのファイルが完全にアップロードされ、1ではないされています。テンプレートの

私のルータがそうのようなものです:

Router.route('travel_request', { 
    path: '/travel/travel_requests/new', 
    yieldTemplates: { 
     'travel_request': {to: 'body'} 
    }, 
    data: function(){ 
     return { 
      userId: Meteor.userId(), 
      createdAt: new Date(), 
      mdApproval: 0, 
      mApprovalDate: null, 
      mdRejectReason: "", 
      aoApproval: 0, 
      aoApprovalDate: null, 
      aoRejectReason: "", 
      travelCostEstimates: {localTransportFare: 0, airFare: 0, hotelFare: 0, overseasFare: 0, businessExpenses: 0, miscFare:0, totalFare: 0}, 
      travelRequestRows: [], 
      images: [], 
     }; 
    }, 
    /* 
    onBeforeAction: function(){ 
     if (Roles.userIsInRole(Meteor.userId(), 'admin')){ 
      sweetAlert('Admin cannot log Travel Requests.'); 
      Router.go('home'); 
     } else { 
      this.next(); 
     } 
    }, 
    */ 
    subscriptions: function(){ 
     Meteor.subscribe('users'); 
     // this.subscribe('travel.images').wait(); 
    }, 
    action: SignedIn 
}); 

Imageコレクションがそうのように定義されています。

Image = new FS.Collection("images", { 
    /* the file director: .meteor/local/uploads */ 
    stores:[new FS.Store.FileSystem("images",{path:Meteor.settings.uploadRoot+"/uploads"})], 
    filter: { 
     allow: { 
      contentTypes: ['image/*', 'application/pdf'] //allow only images and pdf in this FS.Collection 
     } 
    } 
}); 

if(Meteor.isServer){ 
    Image.allow({ 
     'insert': function() { 
      // add custom authentication code here 
      return true; 
     }, 
     'update': function() { 
      return true; 
     }, 
     'download':function(){ 
      return true; 
     } 
    }); 
} 

流星のバージョンはMeteor 1.4.3.2です。

エラーが何であるか、そしてクライアントが最新の情報をリフレッシュする理由と解決方法についての助けがあれば、非常に感謝しています。

+0

を行う方法を作業する必要がありますあなたが提案してみてくださいましたhttps://github.com/arunoda/meteor-up-legacy/issues/150?ここからの方法は? – Styx

+0

@Styx:はい、助けてくれませんでした – nakiya

答えて

1

問題は、ファイルシステムにアップロードされたファイルを保存していることです。新しいファイルが検出されると、meteorは再構築して再起動します。これはあなたの不安定な結果を説明します。

この質問は、同様の問題について説明します。Image Upload using fs.writeFile() shows corrupt Images

をあなたは不幸である、完全にファイルシステムへのアクセスを回避する必要がありますが、あなたはそれに

+0

流星プロジェクトフォルダの外にファイルを保存するだけです。 – Styx

+0

ファイルシステムを境界外として扱う必要があります。ドッカーコンテナで実行している場合、ファイルシステムは準備ができているため、実行できません。それが流星の階層の外にある場合は、とにかくこれらのファイルを提供することはできません。 S3やfilestackのようなサービスを使う – Mikkel

関連する問題