流星云和 lepozepo:cloudinary

Meteor Cloudinary and lepozepo:cloudinary

我已经设置了一个 barbone meteor 应用程序来测试 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 服务器。我很难弄清楚哪里出了问题。我可以帮忙找到一些提示吗?

  1. errres 不是应该作为 data-form-data.
  2. 的一部分传递的参数
  3. 当您遇到任何错误时,Cloudinary 总是 returns x-cld-error HTTP header.
  4. 下的错误详细信息

我最终使用了 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流星客户端文件中:

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)
    });
}