Search code examples
asp-classic

ASPupload 'if Not File Is Nothing' always returns false


Using Persits ASPupload component to upload and process files (Classic ASP).

The file is being uploaded via a jQuery ajax form.

I have run into an odd situation, where the customary test if Not File Is Nothing Then always returns false even when the file has most definitely been uploaded (I can see it on the server).

This is my jQuery code:

    var hiddenSignature = $("#hiddenSignature").val();

    var formData = new FormData();

    formData.append('closingPic', $('#closingPic')[0].files[0]);
    formData.append('hiddenSignature',hiddenSignature);

    $.ajax({ 

        url: "ajax_tickets_file.asp?action=cost", 
        type: "POST", 
        enctype: 'multipart/form-data',
        contentType: false,
        processData: false,     
        data: formData, 

        beforeSend: function() {
            ...
        },
        success: function(msg) { 
            ...
       }
    });

And this is the server side code on ajax_tickets_file.asp:

   Set objUpload = Server.CreateObject("Persits.Upload.1")

    With objUpload

       .CodePage = 65001
       .OverwriteFiles = False

       Set file = .Files("closingPic")

       .SaveVirtual defaultUploadsFolder  // a file is indeed saved on the server, at the correct location 
       response.write " saved  "

       if Not file Is Nothing Then
            response.write “we have a file” 
        else
             response.write "no file"   //  this is what I get
        end if

So, as mentioned earlier, I get “no file” printed.

How could this happen?

Thanks


Solution

  • H/T to the owner of Persits ASPupload for helping me

    Code should be:

       .CodePage = 65001
       .OverwriteFiles = False
    
       //these 2 lines should be in reversed order: 'save' before 'set file'
       .SaveVirtual defaultUploadsFolder   
       Set file = .Files("closingPic")