views:

22

answers:

1

Hello all,

When I use uploadify to upload photos to the server I use the following script (The script is placed in the Photo.aspx (this is the view of the UploadController and the Photo action)):

    <script type="text/javascript">
    $(document).ready(function () {
        $("#fileInput").uploadify({
            uploader: "../../Images/uploadify.swf",
            script: "../../Upload/Upload.ashx",
            cancelImg: "../../Images/cancel.png",
            auto: true,
            multi: true,
            folder: "Folder/Photos",
            onError: function (a, b, c, d) {
                if (d.status == 404)
                    alert("Could not find upload script. Use a path relative to: bla ");
                else if (d.type === "HTTP")
                    alert("error " + d.type + ": " + d.info);
                else if (d.type === "File Size")
                    alert(c.name + " " + d.type + " Limit: " + Math.round(d.sizeLimit / 1024) + "KB");
                else
                    alert("error " + d.type + ": " + d.text);
            }
        });
    });  
</script>

Found here

Everything works fine until I've selected the files and the script starts uploading. Error HTTP: 404. This means, it doesn't find the script file. I tried everything: script: "../../Upload.ashx", script: "../Upload.ashx", script: "Upload.ashx", etc..

The Upload.ashx is placed in Views/Upload/Upload.ashx (This folder also contains the Photo.aspx from the UploadController which contains the uploadify script). The scripts are loaded at the end of my page. I don't understand why uploadify can't find the script when I use the 'script: "Upload.ashx"' property. Can someone help with this?

A: 

The reason why you are always getting a 404 is because you should never link directly to a view. Create an action method in a controller that accepts a HttpPostedFileBase file. Here's an article from Phil Haack: http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx

ZippyV
Hello, Thnx for the answer. Yesterday I found the solution, I placed the files wrong, so the script couldn't find the actions or what so ever. At this moment, I don't use a controller, just a generic Handler in which I edit the photos to copy to right place on the server. But thanks for the answer, nice article (hadn't seen that before).
ThijsBour