Dropzone Rails Gem如何发送0个文件
我想知道正确的方法,即使我上传了0个文件,我仍将如何处理仍在发送。我的表格具有大量的输入数据,并且图像是可选的。
我可能可以使用完全独立的AJAX请求发送,该请求的重复是“ SendingMultiple”,否则我不确定在处理此情况时,在Dropzones Solutions的范围内是否有可能。
Dropzone.options.dropzone =
url: '/test/create'
autoProcessQueue: false
clickable: true
uploadMultiple: true
timeout: 180000
parallelUploads: 8
maxFiles: 8
maxFilesize: 5
acceptedFiles: 'image/*'
addRemoveLinks: true
headers: 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
init: ->
dzClosure = this
document.getElementById('submit-button').addEventListener 'click', (e) ->
e.preventDefault()
e.stopPropagation()
dzClosure.processQueue()
return
@on 'sendingmultiple', (data, xhr, formData) ->
formData.append 'item_number', jQuery('#item_number').val()
... more form data
return
@on 'success', (file, responseText) ->
window.location.href = url
return
return
I want to know the right way on how I handle still sending even when I have 0 files uploaded. I have a form that has a lot of data to input and the images are optional.
I could probably send this with an entirely separate Ajax request that is a duplicate of 'sendingmultiple', otherwise I am unsure if this is possible within the confines of dropzones solutions in handling this case.
Dropzone.options.dropzone =
url: '/test/create'
autoProcessQueue: false
clickable: true
uploadMultiple: true
timeout: 180000
parallelUploads: 8
maxFiles: 8
maxFilesize: 5
acceptedFiles: 'image/*'
addRemoveLinks: true
headers: 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
init: ->
dzClosure = this
document.getElementById('submit-button').addEventListener 'click', (e) ->
e.preventDefault()
e.stopPropagation()
dzClosure.processQueue()
return
@on 'sendingmultiple', (data, xhr, formData) ->
formData.append 'item_number', jQuery('#item_number').val()
... more form data
return
@on 'success', (file, responseText) ->
window.location.href = url
return
return
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我找到了一个我认为最好的解决方案。其他任何人都有更好的东西,请提供。
我只是更改了它,因此只有在检测到适合我的情况的任何图像预览时,我们只会覆盖此功能的按钮。因此,我们仍然对控制器上的正常创建/更新是正常的,当没有图像上传时会触发。然后,我在控制器中有一个image_upload_create函数,该功能根据表单中的ID是否具有ID来更新或创建。
对于那些对语法感到困惑的人,该解决方案都是在咖啡本中。
Okay I have found a solution that I think works the best. Anyone else with something better please provide.
I just changed it so we only override the button to this function if we detect any image previews, which works for my situation. So we still have the normal create/update on the controller as normal that fires when no images are uploaded. Then I have an image_upload_create function in the controller that updates or creates depending if it has a id in the forms.
The solution is all in coffeescript for those confused about syntax.