How to respond server-side to routes using Meteor and Iron-Router?

后端 未结 4 1516
无人共我
无人共我 2021-01-27 04:34

I\'m sending a file from client-side to server side using XHR:

$(document).on(\'drop\', function(dropEvent) {
    dropEvent.preventDefault();
    _.each(dropEven         


        
相关标签:
4条回答
  • 2021-01-27 05:00

    You can upload file with use of EJSON and normal meteor "methods" this way you will be able to get access to user data because it is visible only inside methods and publish functions on server side

    this video tutorial may be a good start

    also package CollectionFS provides some upload functionalities. It is now little outdated, but idea stays the same.

    0 讨论(0)
  • 2021-01-27 05:02

    By default, your routes are created as client side routes. This means, a link to that route will be handled in the browser vs. making a server request. But you can also create server side routes by providing a where option to the route. The handler for the server side route exposes the request, response, and next properties of the Connect object. The syntax has changed a little from 0.5.4 to the dev branch so I'll provide both examples depending on which you're using:

    v0.5.4

    Router.map(function () {
      this.route('upload', {
        where: 'server',
        handler: function () {
          var request = this.request;
          var response = this.response;
          // do whatever
        }
      });
    });
    

    dev

    Router.map(function () {
      this.route('upload', {
        where: 'server',
        action: function () {
          var request = this.request;
          var response = this.response;
          // do whatever
        }
      });
    });
    
    0 讨论(0)
  • The same people who brought you iron-router also have meteor-file which will do the file transfer for you, or you can use as an example for your own implementation

    0 讨论(0)
  • 2021-01-27 05:11

    Meteor Router (now deprecated) has server side routing support:

    Meteor.Router.add('/upload', 'POST', function() {
      // do stuff
    });
    
    0 讨论(0)
提交回复
热议问题