I'm trying to use the swfupload plugin to upload files. The thing is, I want the user to be able to switch the directory to upload to.
The strange thing is (and maybe this is due to my limited knowledge of jQuery) that it seems like I have the correct directory when checking it with an alert, but still the upload goes to the previously selected directory.
I.e. if I open the page, and click on the upload link, a div called uploadPanel is shown, which loads the swfupload. I can do the first upload fine. But if I then choose a different directory it doesn't work. I have put in an alert for testing that the variable for the current directory is correct. This alert always shows the current directory correctly. But still when the action method in the server code is called, the directory is always for the first selected directory that I had in the first upload.
Here's the jQuery code:
<script type="text/javascript">
var uploadDir;
$(function () {
$("#uploadPanel").hide();
var auth = "<% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>";
loadFileManager();
$("#uploadLink").click(function (event) {
$('#uploadPanel').show();
alert("uploadDir: " + uploadDir); //NOTE!!!: This shows the correct current directory, and yet, in post_params below, a previous directory is still sent to the action method in the Controller. How is this possible when the alert shows the correct directory?
$("#inputFile").makeAsyncUploader({
upload_url: "/Upload/AsyncUpload/",
flash_url: '/Scripts/swfupload.swf',
button_image_url: '/Scripts/blankButton.png',
post_params: { token: auth, currentDirectory: uploadDir },
use_query_string: true,
disableDuringUpload: 'INPUT[type="submit"]'
});
$("#closeButton").click(function () {
$("#uploadPanel").hide();
$("#inputFile_completedMessage").hide();
});
});
});
</script>
Note: the uploadDir is set elsewhere, in a separate js file. But the point is, the value of it is always correct in the alert, so why not in the call to the action method?