我正在使用Jquery文件上传,我有一些看起来像这样的coffeescript:
$('.fileupload').fileupload
dataType: "json"
add: (e, data) ->
file = data.files[0]
types = /(\.|\/)(gif|jpe?g|png)$/i
if (types.test(file.type) || types.test(file.name))
data.submit()
else
alert("Oops, " + file.name + " is not a supported filetype")
progress: (e, data) ->
done: (e, data) ->
基本上,我想要做的是根据上传的文件类型发送到不同的URL。例如,如果上传了pdf,我想将其发送到www.website.com/process/pdf
,而如果是png / gif / jpeg则将其发送到www.website.com/process/image
。
这可能是jQuery文件上传的客户端吗?
答案 0 :(得分:0)
您可以更改数据对象
$('.fileupload').fileupload
dataType: "json"
add: (e, data) ->
file = data.files[0]
types = /(\.|\/)(gif|jpe?g|png)$/i
pdf = /(\.|\/)(pdf)$/i
if (types.test(file.type) || types.test(file.name))
data.url = 'www.website.com/process/image'
data.submit()
else if (pdf.test(file.type) || pdf.test(file.name))
data.url = 'www.website.com/process/pdf'
data.submit()
else
alert("Oops, " + file.name + " is not a supported filetype")
progress: (e, data) ->
done: (e, data) ->
jQuery File Upload: how to change the upload url dynamically