簡體   English   中英

在流星中使用圖像集

[英]Use an Image Collection in Meteor

我正在構建一個流星應用程序,該應用程序通過https://github.com/crazytoad/meteor-collectionapi的 HTTP請求與桌面客戶端進行通信

桌面客戶端以不規則的時間間隔生成圖像,我希望Meteor網站僅顯示最新生成的圖像(最好是實時顯示)。 我最初的想法是使用對base64 imagedata的單例集合使用PUT請求,但是我不知道如何在Web瀏覽器中將其轉換為圖像。 注意:圖像都非常小(小於1 MB),因此應該不需要使用gridFS。

我意識到這個想法可能是完全錯誤的,因此,如果我完全走錯了路,請提出更好的行動方案。

您需要編寫一個中間件,以使用正確的MIME類型提供圖像。 例:

WebApp.connectHandlers.stack.splice (0, 0, {
  route: '/imageserver',
  handle: function(req, res, next) {

    // Assuming the path is /imageserver/:id, here you get the :id
    var iid = req.url.split('/')[1];

    var item = Images.findOne(iid);

    if(!item) {
      // Image not found
      res.writeHead(404);
      res.end('File not found');
      return;
    }

    // Image found
    res.writeHead(200, {
      'Content-Type': item.type,
    });
    res.write(new Buffer(item.data, 'base64'));
    res.end();

  },

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM