本文介绍了流星文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到之前已经提到过这个问题,但是从 Meteor.http 已经没有了。我仍然抓住流星的概念,文件上传完全躲避我。

这是我的问题:

因此,在我认为是正确的方法中,

Meteor.http.call(POST,url,[options],[asyncCallback])
你对网址做了什么?在流星的客户机/服务器的JavaScript关系,它似乎并没有真正使用urls那么多。



如果有人有流星文件上传的基本示例,那就是

在filepicker.io。他们处理上传,将其存储到您的S3,并返回到您可以转储到您的数据库的网址。


  1. Wget filepicker脚本到你的客户文件夹中。

      wget https://api.filepicker.io/v0/filepicker.js $插入一个filepicker输入标签

    $ $
    $ <$> p $ p> < input type =filepickerid =attachment>


  2. 在启动时,初始化:

      Meteor.startup(function(){
    filepicker.setKey(Your FILEPICKER API KEY);
    filepicker.constructWidget(document.getElementById('附件'));
    });


  3. 附加一个事件处理程序

    <$ ($ {$ b $'change #attachment':function(evt){
    console.log(evt.files);
    } Template.templateNameHere.events
    });


如何用流星处理文件上传?对不起,这里是新的,是否可以复制相同的答案两次?任何知道更好的人都可以随意编辑这个。)


I see that this has been asked here before, but nothing since Meteor.http has been available. I'm still grasping the concepts of Meteor and file uploads are totally eluding me.

Here's my question:
So, in what I believe to be the right method,
Meteor.http.call("POST", url, [options], [asyncCallback])
what do you put for the url? With the client/server javascript relationship in meteor, it doesn't seem like it really uses urls that much.

If anyone has a basic example of a file upload in meteor, that would just be extra awesome.

解决方案

Take a look at filepicker.io. They handle the upload, store it into your S3, and return to you the url that you can dump into your db.

  1. Wget the filepicker script into your client folder.

    wget https://api.filepicker.io/v0/filepicker.js
    

  2. Insert a filepicker input tag

    <input type="filepicker" id="attachment">
    

  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

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

(I had posted on How would one handle a file upload with Meteor? Sorry. I'm new here. Is it kosher to copy the same answer twice? Anyone who knows better can feel free to edit this.)

这篇关于流星文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 09:49