我的第一个上传示例有一个奇怪的问题。问题是SWF文件正在尝试从http://localhost:8080/myapp/uploadify/uploadify.swf
加载,但该文件位于http://localhost:8080/myapp/resources/uploadify/uploadify.swf
。
出于这个原因,在Firebug和Chrome Dev工具中,我得到了这个文件的404。
以下是代码:
<link type="text/css" rel="stylesheet"
href="<c:url value="/resources/css/myapp.css"/>" />
<link type="text/css" rel="stylesheet"
href="<c:url value="/resources/uploadify/uploadify.css"/>" />
<link type="text/css" rel="stylesheet"
href="<c:url value="/resources/jquery-ui/jquery-ui-1.8.18.custom.css"/>" />
<script type="text/javascript"
src=<c:url value="/resources/uploadify/jquery-1.4.2.min.js" />></script>
<script type="text/javascript"
src=<c:url value="/resources/uploadify/jquery-ui-1.8.22.custom.min.js" />></script>
<script type="text/javascript"
src=<c:url value="/resources/uploadify/swfobject.js" />></script>
<script type="text/javascript"
src=<c:url value="/resources/uploadify/jquery.uploadify.v2.1.4.min.js"/>></script>
<!-- Scripts to display the dialog and to initialize and control the
uploadify component behavior.
-->
<script type="text/javascript">
function submitUpload() {
try {
fileSelectorElement.uploadify('upload');
} catch (e) {
alert("Failed to start document upload." + e);
}
}
function showUploadDialog() {
try {
$('#uploadDialog').dialog({
modal: true,
buttons: {
"Cancel": function() {
$(this).dialog("close");
},
"Upload": function() {
submitUpload();
}
},
minWidth: 450,
closeOnEscape: false,
title: "Upload a document"
});
} catch (e) {
alert("Could not create upload dialog. " + e);
}
}
$(document).ready(function() {
try {
$("#inputFile").uploadify({
'swf': '<c:url value="/resources/uploadify/uploadify.swf" />',
'script' : '<c:url value="/upload"/>',
'scriptData' : {'dealId': dealId, 'agendaId': agendaId},
'buttonImage': '<c:url value="/resources/uploadify/upload-file.png" />',
'cancelImg' : '<c:url value="/resources/uploadify/cancel.png" />',
'folder' : '/uploads',
'height': 31,
'width': 300,
'multi': false,
'method' : 'post',
'auto' : true,
'onUploadError': function(a, b, c, errorObj) {
alert("Not working: " + errorObj);
},
'onComplete' : function(event, ID, fileObj, response, data) {
if(response == 'success')
alert("Successfully uploaded!");
else
alert("Failed");
}
});
} catch (e) {
alert("Cannot initialize uploadify element " + e);
}
showUploadDialog();
});
</script>
<div id="uploadDialog" style="display: none">
<p>Upload a document here:</p>
<input type="file" id="inputFile" name="inputFile"/>
<form:form modelAttribute="uploadbean" method="post"
enctype="multipart/form-data">
</form:form>
</div>
<div id="uploadPitchSuccess" style="display: none;">
<p class="success">File uploaded successfully.</p>
</div>
<div id="uploadPitchError" style="display: none;">
<p class="success">The file could not be uploaded.</p>
</div>
我尝试使用'swf'参数的相对路径和绝对路径。以及动态(如上所述)和硬编码路径。无论我设定什么价值,路径都不会改变。
我也尝试将swf放在http://localhost:8080/myapp/uploadify/uploadify.swf
中,但它仍然会抛出404。
我想我必须遗漏一些非常明显的东西;但我不能简单地看到它是什么。
感谢您的帮助