如何在node.js上实现jQuery直接上传到Cloudinary [英] How to implement jQuery direct upload to Cloudinary on node.js

查看:112
本文介绍了如何在node.js上实现jQuery直接上传到Cloudinary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过他们的jQuery插件直接上传到Cloudinary到Node.js应用程序,我想知道是否有人可以帮助我缩小他们示例中的一些空白。

I'm trying to implement direct uploads to Cloudinary via their jQuery plugin to a Node.js application, and am wondering if anyone can help me close some gaps in their examples.

以下是解释如何操作的博文:

Here's the blog post that explains how to do it:

http: //cloudinary.com/blog/direct_image_uploads_from_the_browser_to_the_cloud_with_jquery

在其他开发框架和高级用法部分中,我坚持的部分是:

In the "Other development frameworks and advanced usage" section, the part I'm stuck on is:


  • 将data-form-data设置为上传API参数的JSON表示。必填字段为api_key,时间戳,签名和回调。 ,

更具体地说:


  • 需要在服务器端生成签名以进行正确的身份验证。

似乎没有任何示例究竟如何实现这一点。

There doesn't seem to be any example of exactly how to achieve this.

示例如下:

<input name="file" type="file" 
       class="cloudinary-fileupload" data-cloudinary-field="image_upload" 
       data-form-data=" ... html-escaped JSON data ... " ></input>

以及数据表格数据未转义的JSON内容为:

and the unescaped JSON content of data-form-data is:

{ "timestamp":  1345719094, 
  "callback": "https://www.example.com/cloudinary_cors.html",
  "signature": "7ac8c757e940d95f95495aa0f1cba89ef1a8aa7a", 
  "api_key": "1234567890" }

你如何产生签名?我知道我需要在node.js中执行此操作,看起来它需要在生成表单时发生,尽管我可以告诉签名需要包含时间戳 - 这肯定会在用户发布时过时已填写表格?

How do you go about generating the signature? I understand I need to do this in node.js, and it seems like it needs to happen when the form is generated, although from what I can tell the signature needs to include the timestamp - which would surely be outdated by the time the user has filled out the form?

请求身份验证的文档在此处: http ://cloudinary.com/documentation/upload_images#request_authentication

The documentation for request authentication is here: http://cloudinary.com/documentation/upload_images#request_authentication

cloudinary_npm 模块,我正在使用, uploader.coffee 中有一个名为 direct_upload 的方法似乎是帮助实现这一目标,但我不清楚如何实际将它们绑定在一起。

In the cloudinary_npm module, which I am using, there is a method in uploader.coffee called direct_upload which seems like a helper to make this happen, but I'm not clear on how to actually bind it all together.

这两个框架在博客文章中有实例, Rails和Django通过他们自己的帮助器来提取这种复杂性,例如在Django中,您将 {{form.image}} 添加到表单中,该表单输出 image = cloudinary.forms.CloudinaryJsFileField() - 遗憾的是,如何在任何其他服务器端环境中复制此内容都不包括在内。

The two frameworks with real examples in the blog post, Rails and Django, abstract this complexity through their own helpers, e.g. in Django you add {{ form.image }} to your form, which outputs the result from image = cloudinary.forms.CloudinaryJsFileField() - unfortunately how to replicate this in any other server-side environment is not covered.

如果有人可以对此有所了解,或者分享一个要点或关于如何使其端到端工作的例子,我非常感谢。

If anyone can shed any light on this, or share a gist or example on how to make it work end-to-end, I'd greatly appreciate it.

推荐答案

请看一下在 https://github.com/cloudinary的uploader.image_upload_tag /cloudinary_npm/blob/67b7096c7fac2c2bed06603912966495d59dfa34/lib/uploader.coffee#L220
它返回一个输入标签的html,可以与jquery.cloudinary.js一起使用,直接将图像上传到cloudinary。
它将成为下一个npm版本的一部分(预计下周某个时候)。
至于时间戳 - 签名有效期为1小时,因此用户应该有足够的时间上传图片。

Please take a look at the uploader.image_upload_tag at https://github.com/cloudinary/cloudinary_npm/blob/67b7096c7fac2c2bed06603912966495d59dfa34/lib/uploader.coffee#L220 It returns the html for an input tag that can be used together with jquery.cloudinary.js to upload images directly to cloudinary. It will be part of the next release of the npm (expected sometime next week). As for the timestamp - the signature is valid for 1 hour, so there should be plenty of time for the user to upload the image.

这篇关于如何在node.js上实现jQuery直接上传到Cloudinary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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