使用Dropzone将文件上传到Google云端硬盘 [英] Upload files to Google Drive using Dropzone
本文介绍了使用Dropzone将文件上传到Google云端硬盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我当前用于上传任务的代码:
This is my current code used for the uploading task:
$imagesDropzone.dropzone
init: ->
this.on 'sending', (file, xhr) ->
xhr.setRequestHeader 'Content-Type', file.type
url: 'https://www.googleapis.com/upload/drive/v2/files?uploadType=media'
method: 'post'
maxFileSize: 5
paramName: 'images-dropzone-input'
headers:
'Authorization': "Bearer #{ uploadBundle.accessToken }"
addRemoveLinks: 'dictRemoveFile'
它不起作用(所有上传的文件都是破碎)。
我知道我需要做这样的事情:
And it doesn't work (all uploaded files are broken). I know I need to do something like this:
xhr.send file
但我不知道该把这个电话放在哪里。我怎样才能重写Dropzone的 send
行为?
But I don't know where to put this call. How can I override the send
behavior of Dropzone?
推荐答案
看看Dropzone的源代码,我想通过覆盖实例方法 uploadFiles
来做到这一点:
After take a look on the source code of Dropzone, I figure out a way to do it by overriding the instance method uploadFiles
:
imagesDropzoneInstance = new Dropzone '#imagesDropzone',
url: 'https://www.googleapis.com/upload/drive/v2/files?uploadType=media'
method: 'post'
maxFileSize: 5
paramName: 'images-dropzone-input'
headers:
'Authorization': "Bearer #{ uploadBundle.accessToken }"
addRemoveLinks: 'dictRemoveFile'
imagesDropzoneInstance.uploadFiles = (files) ->
uploadFiles: (files) ->
.. copy the uploadFiles method of Dropzone, modify, then paste here..
# Add the end:
xhr.send files[0] # This overrides the default upload behavior.
这篇关于使用Dropzone将文件上传到Google云端硬盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文