How to upload file at the same time as the rest of the form is submitted?

Last post 12-16-2010, 8:11 PM by Kenneth. 4 replies.
Sort Posts: Previous Next
  •  12-15-2010, 2:25 PM 65374

    How to upload file at the same time as the rest of the form is submitted?

    Hi there

    I am having a problem, I have read all the forum and documentation and I can not find the answer...

    I use a form with ASP upload that can upload 1 file. The upload is set to start manually because I'd like that the inserted picture is uploaded when the form is triggered.

    I tried using doStart function that uploads the file and putting the function trigger to the SUBMIT button of the form. The:

    uploadobj.startupload() is working but it doesn't finish uploading because the form is then submiited in a second and upload fails (uploads only partly).

    How can I stop the form from submitting and let the file upload finish first (and start submitting when I press submit)?

    Or is the only way to manually trigger file upload with special button and submit the rest of the form with submit? I find that non practical. On top of that if one uses custom buttom to upload file he can send 100 files but I want to allow only ONE per form. Automatic upload also doesn't work for the same reason and I still have to resize pictures after upload. So the only way I see is using the "upload when submit" option but then file is not uploaded completely.

    Please help...

    PS - To make the question more simple: Is there a way to use your module in the "normal web way", that means instead of a filefield in a form? I have a form with a filefield and I'd like to exchange file filefield with your code so that file would be uploaded when the rest of the form is submitted. But the file could also be empty (so I don't select a file at all) and the form would be submitted. I hope that is possible ;-)

  •  12-16-2010, 1:08 AM 65375 in reply to 65374

    Re: How to upload file at the same time as the rest of the form is submitted?

    Hi jerry2,
     
    Please try the example below
     
     
    <%@  language="VBScript" %>
    <!-- #include file="aspuploader/include_aspuploader.asp" -->
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Form - Start uploading manually </title>
        <link href="demo.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div class="demo">
            <h2>
                Start uploading manually</h2>
            <p>
                This sample demonstrates how to start uploading manually after file selection vs
                automatically.</p>
            <!-- do not need enctype="multipart/form-data" -->
            <form id="form1" method="POST">
                <%
                    Dim uploader
                    Set uploader=new AspUploader
                    uploader.MaxSizeKB=10240
                    uploader.Name="myuploader"
                    uploader.InsertText="Upload File (Max 10M)"
            
                     uploader.AllowedFileExtensions="*.jpg,*.png,*.gif,*.zip"
                    uploader.SaveDirectory="savefiles"
                    uploader.ManualStartUpload=true
                    
                %>
                <%=uploader.GetString() %>
                <br />
                <br />
                <br />
                <button id="submitbutton" onclick="doStart();return false;">
                    Start Uploading Files</button>
                <input type="submit" value="Submit" onclick="showSubmitMessage()" id="submit"  style="visibility:hidden"/>
             
            </form>
            <br />
            <br />
            <br />
            <%

    If Request.Form("myuploader")&""<>"" Then

        Dim list,i
        list=Split(Request.Form("myuploader"),"/")

        For i=0 to Ubound(list)
            if i>0 then
                Response.Write("<hr/>")
            end if
            Dim mvcfile
            Set mvcfile=uploader.GetUploadedFile(list(i))

            Response.Write("<div style='font-family:Fixedsys'>")
            Response.Write("Uploaded complete")
            Response.Write("</div>")
        Next
    End If

            %>
        </div>
    </body>
    </html>

    <script>
    function showSubmitMessage()
    {
    //submit page
    }
        function doStart()
        {
        
            var uploadobj = document.getElementById('myuploader');
            if (uploadobj.getqueuecount() > 0)
            {
                uploadobj.startupload();
                
            }
            else
            {
                alert("Please browse files for upload");
            }
        }
        
        function CuteWebUI_AjaxUploader_OnTaskComplete(task)
        {
            //fire after upload complete
              var submit=document.getElementById("submit");
              submit.click();
        }
    </script>
    Regards,
     
    Ken
  •  12-16-2010, 7:19 AM 65380 in reply to 65375

    Re: How to upload file at the same time as the rest of the form is submitted?

    Thanx but this doesn't work for me :-(

    I think documentation is very poor for such a great product as this. The OnTastComplete is not even listed in documentation. Some other things like UploaderEvents have no description what they do etc. :-(

    In my case, the button just starts uploading and submits the form (upload only 64kB of course) ;-(

    I am really trying hard to use this extension I have allready paid :-/

    Is there a way to use normal file upload fields with this extension?

  •  12-16-2010, 8:08 AM 65383 in reply to 65380

    Re: How to upload file at the same time as the rest of the form is submitted?

    Ok you should use: 

    <input type="button" id="submitbutton" value="submit" onclick="doStart();">

    for the button, this way it works.

    But I have a problem. Now if I don't want to upload picture in a form, the button triggers nothing (I have removed the return false;) because obviously the OnTaskComplete is not triggered.

    How could I detect if the upload queue has a file and according to that trigger either the upload/submit or only submit? Is it possible?

  •  12-16-2010, 8:11 PM 65393 in reply to 65383

    Re: How to upload file at the same time as the rest of the form is submitted?

    Hi jerry2,
     
    see the red code, it shows you how to detect if the upload queue has a file or not .
     
        if (uploadobj.getqueuecount() > 0)
            {
                uploadobj.startupload();
                
            }
            else
            {
                alert("Please browse files for upload");
            }
     
    If it is not  enough, please explain you requirement on detail.
     
    Regards,
     
    ken
View as RSS news feed in XML