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

问题描述

我试图用Lepozepo / cloudinary上传一张照片



这是我的服务器和客户端配置



server:

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

客户:

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

我试图用表单上传图片



html表单代码:

 < form> 
< input type =fileid =userimagename =userimage/>
<按钮类型=提交>上传< /按钮>
< / form>

这是我的这个模板事件

  Template.signup.events({
//提交注册表单事件
'提交表单':function(e,t){
//防止默认动作
e.preventDefault();

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

当我点击上传按钮时,什么也没有发生,我刚刚收到一个错误

  error:uncaught TypeError:无法在FileReader上执行'readAsDataURL':参数1不是'Blob'类型'

我能做些什么来完成这项工作?

解决方案

我找到了解决方法。


  1. Lepozepo / cloudinary Cloudinary.upload 方法文件参数是一个数组,我只是添加下面的代码:

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


它工作正常


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

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

10-14 17:54