流星:阴天 [英] Meteor: Cloudinary

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

问题描述

I am trying to upload a photo with Lepozepo/cloudinary

This is my server and client config

server:

Cloudinary.config({
  cloud_name: '*****',
  api_key: '******',
  api_secret: '********'
});

client:

$.cloudinary.config({
  cloud_name: "*******"
});

I tried to upload the image with a form

html form code:

<form>
   <input type="file" id="userimage" name="userimage"/>
   <button type="submit">Upload</button>
</form>

And this is my this is the event for the template

Template.signup.events({
    // Submit signup form event
    'submit form': function(e, t){
        // Prevent default actions
        e.preventDefault();

    var file = $('#userimage')[0].files[0];
    console.log(file)
    Cloudinary.upload(file, function(err, res) {
          console.log("Upload Error: " + err);
          console.log("Upload Result: " + res);
        });
    }       
});

When i click on upload button nothing happen, I just got an error

 error: uncaught TypeError: Failed to execute 'readAsDataURL' on `'FileReader': parameter 1 is not of type 'Blob'.`

What can I do to make this work ?

解决方案

I find a way to solved it.

  1. Lepozepo/cloudinary Cloudinary.upload method file parameter is an array, I just add this code:

    var files = []
    var file = $('#userimage')[0].files[0];
    files.push(file)
    console.log(files)
    

And it work fine

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆