0

我的第一个 Uploadify 示例遇到了一个奇怪的问题。问题是试图从 加载 SWF 文件http://localhost:8080/myapp/uploadify/uploadify.swf,但该文件位于http://localhost:8080/myapp/resources/uploadify/uploadify.swf.

出于这个原因,在 Firebug 和 Chrome 开发工具中,我得到了这个文件的 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。

我想我必须在这里遗漏一些非常明显的东西;但我不能简单地看到它是什么。

谢谢你的帮助

4

0 回答 0