如何使用 Carrierwave、Backbone、Plupload 将异步文件上传附加到模型?

发布于 2024-12-19 03:35:19 字数 486 浏览 2 评论 0原文

我正在努力实现 Thoughtbot Q/A 演讲前 5 分钟所讨论的内容;异步上传文件,然后保留模型及其附加的文件。

http://ui.thoughtbot.com/assets/backbone_js_rails_chat_episode_1_part_1.m4a

我已经设置up 后端上的 Carrierwave 和客户端上的 Plupload,我能够使请求并上传文件。但是我不确定如何发送响应中讨论的令牌,然后保留模型。

所以我有一个带有标题输入和一个添加图像的 plupload 按钮的表单,然后我有一个应该进行上传的保存按钮,然后保存模型(照片,带有安装的 Carrierwave 上传器和标题属性)

如何我可以将这两个请求合并到一个按钮上提交吗? 这一切将如何实施?

Im trying to achieve what's talked about in the first 5 minutes of the Thoughtbot Q/A talk; Upload a file async and then persist the model with the file attached to it.

http://ui.thoughtbot.com/assets/backbone_js_rails_chat_episode_1_part_1.m4a

I've set up carrierwave on the backend and Plupload on the client and am able to make the request and upload the file. However I'm unsure about how I would send the token being talked about back in the response and then persist the model.

So I have a form with a title input and a plupload button that adds the image, I then have a save button that's supposed to make the upload, then save the model (Photo, with a mounted Carrierwave uploader and a title attribute)

How would I combine the two requests into being submitted on one single button?
How would all this be implemented ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情归归情 2024-12-26 03:35:19

如果 iframe 目标(上传)位于同一服务器上,您可以返回类似于 JSONP 的内容。然后

var functionUpload(model, $inputform) {
   var cbName = 'cb' + Math.floor((Math.random()*100000)+1));
   document[cbName] = function (id) {
     model.set({binID: id}); // or just refetch
   } 
   $inputform.attr('action', uploadURL+'callback='cbName);
   $inputform.trigger('submit');
}

让上传脚本返回

<script>
  document.parent.cb12354(123);
</script>

If the iframe target (the upload) is on the same server you can return something analogous to a JSONP. something like

var functionUpload(model, $inputform) {
   var cbName = 'cb' + Math.floor((Math.random()*100000)+1));
   document[cbName] = function (id) {
     model.set({binID: id}); // or just refetch
   } 
   $inputform.attr('action', uploadURL+'callback='cbName);
   $inputform.trigger('submit');
}

Then have the upload script return

<script>
  document.parent.cb12354(123);
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文