流星云和lepozepo:cloudinary

时间:2015-08-06 09:56:59

标签: meteor cloudinary

我已经设置了一个barbone meteor app来测试lepozepo:cloudinary包。

if (Meteor.isClient) {

  $.cloudinary.config({cloud_name:"name"})

  Template.hello.events({
    'click button': function () {
      // increment the counter when button is clicked
      Session.set('counter', Session.get('counter') + 1);
    },

    "change input[type='file']": function (event) {
      files = event.currentTarget.files
      Cloudinary.upload(files,{err:function(e){console.info(e)},res:function(e){console.info(e)}})

    }

  });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
Cloudinary.config({cloud_name: 'name',api_key: '***********',api_secret: '***********'})
  });
}

请求有效负载是:

------WebKitFormBoundaryU4RVLNgyBJWMIyd6
Content-Disposition: form-data; name="api_key"

***************
------WebKitFormBoundaryU4RVLNgyBJWMIyd6
Content-Disposition: form-data; name="signature"

e9631cd9db0b576c9756285ca4a94b386281121c
------WebKitFormBoundaryU4RVLNgyBJWMIyd6
Content-Disposition: form-data; name="timestamp"

1438845000
------WebKitFormBoundaryU4RVLNgyBJWMIyd6
Content-Disposition: form-data; name="file"

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wcXDwcsJpcKdQAAG0FJREFUeNrtfXl8ldW19rPWe04GIGgVxAGLt4MRrVMhIyEnCWKjmZASpVJxaPVqQnvrrdaqrViHtref2qsloP1sreCEURmSYAQkOYGQiaCoV6VcFVBUtA4QINN517p/RBF49wkJOcMLZv3Dj5Pk7L3Xevaa9tprA4P0tSY6kheXNGnKsR7RRBE5VQnHAUhQ1QQGEkBIUNAwEsQAskuJdxGhDUAbFG0g2gnCOzawcajseMvv9wcGAeBWmj2bU1e3niM2fAR8T4HTSDURzMeG4usFCLDibSVsJGCjqjSpx1vT8uLiTwYBEK3dnV1wBgmyiZAjCh8TjonwFFRUXmWiVSRYJUMC/ubq6p2DAAgjJecUn

Content-Disposition: form-data; name="err"

function (e){console.info(e)}
------WebKitFormBoundaryU4RVLNgyBJWMIyd6
Content-Disposition: form-data; name="res"

function (e){console.info(e)}
------WebKitFormBoundaryU4RVLNgyBJWMIyd6--

我总是得到

POST https://api.cloudinary.com/v1_1/name/image/upload 400 (Bad Request)

来自Cloudinary服务器。我很难搞清楚什么是错的。我可以帮忙找一些提示吗?

2 个答案:

答案 0 :(得分:1)

  1. errres不是应该作为data-form-data的一部分传递的参数。
  2. 当您遇到任何错误时,Cloudinary始终会在x-cld-error HTTP标头下返回错误的详细信息。

答案 1 :(得分:0)

我最终使用了nekojira软件包,我发现它更加简单易用: github repository here

配置:

客户级

$.cloudinary.config({ cloud_name: '****', api_key: '*****'})

服务器级别

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

实施

在Cloudinary中创建unsigned tag

在你的模板中:

<template name="cloudy">
    <form id="test" class="ui message"></form>
</template>

在你的javascript meteor客户端文件中:

Template.cloudy.rendered = function() {

$("#test").append($.cloudinary.unsigned_upload_tag("my_unsigned_tag", { cloud_name: '****' },{ multiple: true }))
    .bind('cloudinarydone', function(e, data) {
         console.info("UPLOADED")
    }).bind('cloudinaryprogress', function(e, data) { 
         console.info(data.loaded,data.total)
    });
}