How would one handle a file upload with Meteor?

后端 未结 12 1481
不知归路
不知归路 2020-12-07 07:56

What would be the canonical way to handle a file upload with Meteor?

12条回答
  •  悲哀的现实
    2020-12-07 08:18

    I used http://filepicker.io. They'll upload the file, store it into your S3, and return you a URL where the file is. Then I just plop the url into a DB.

    1. Wget the filepicker script into your client folder.

      wget https://api.filepicker.io/v0/filepicker.js
      
    2. Insert a filepicker input tag

      
      
    3. In the startup, initialize it:

      Meteor.startup( function() {
          filepicker.setKey("YOUR FILEPICKER API KEY");
          filepicker.constructWidget(document.getElementById('attachment'));
      });
      
    4. Attach a event handler

      Templates.template.events({
          'change #attachment': function(evt){
              console.log(evt.files);
          }
      });
      

提交回复
热议问题