我正在尝试通过表单上传 csv 文件,但在 Mac OS X 10.5.8 上遇到问题。这是相关的代码:
template = Handlebars.compile '''
<form action="/dashboard/csv-upload/" enctype="multipart/form-data" method="post" class="csv-upload">
<p>
<label for="id_uploaded_file" style="float:left;">Upload a CSV file:</label>
<input class="span2" name="uploaded_file" id="id_uploaded_file" type="file">
</p>
</form>
'''
class exports.uploadController extends Backbone.View
el: '#main-container'
events:
'submit form.csv-upload' : '_csvUpload'
initialize: () =>
@render()
render: () =>
return @ if @isRendered
@isRendered = true
_csvUpload : (e) =>
e.preventDefault()
file = @$('#id_uploaded_file')[0].files[0]
if not file
alert "Please select a file to upload, first."
return false
console.log(file.type)
if file.type != "text/csv" and file.type != "text/plain"
alert "Please upload a CSV or TXT file"
return false
我遇到的问题是即使我上传 .csv 文件,我也会在 Mac OS X 10.5.8 上收到“请上传 CSV 或 TXT 文件”错误。console.log 返回一个空白字符串。这是一个屏幕截图:
我试过在谷歌上搜索,但没有找到任何东西。我也尝试过使用 Safari 和 Chrome。File 对象在 OS X 10.5.8 上没有显示类型属性吗?