aspSmartUpload and Ajax

Discussion in 'ASP General' started by magix8@gmail.com, Feb 11, 2008.

  1. Guest

    Hi,

    anyone have experience on implement aspSmartUpload with Ajax ?
    as aspSmartUpload required ENCTYPE="multipart/form-data"in FORM, how
    can we achieve this in Ajax?

    Basically, I have a <input type="file" id="myfile">, after user browse
    the file and I will sendRequest via Ajax (using GET method), so that
    the filepath is send to nextpage.asp for upload.

    var http = getXMLHTTPRequest();
    function sendRequest(t, f)
    {

    var myurl = 'nextpage.asp?filepath=' +
    document.getElementById("myfile").value + '&f=' + f + '&t=';

    myRand = parseInt(Math.random()*999999999999999);
    var modurl = myurl + t + "&rand=" + myRand;
    http.open("GET", modurl, true);
    http.onreadystatechange = handleResponse;
    http.send(null);
    }

    Does this make senses ?
    in nextpage.asp, we called for request.querystring("filepath") ?

    But how should the ENCTYPE="multipart/form-data" being included in
    this case? or is there others ?

    any thoughts?

    Thank you very much.

    cheers,
    Magix
    , Feb 11, 2008
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > Hi,
    >
    > anyone have experience on implement aspSmartUpload with Ajax ?
    > as aspSmartUpload required ENCTYPE="multipart/form-data"in FORM, how
    > can we achieve this in Ajax?
    >
    > Basically, I have a <input type="file" id="myfile">, after user browse
    > the file and I will sendRequest via Ajax (using GET method), so that
    > the filepath is send to nextpage.asp for upload.
    >
    > var http = getXMLHTTPRequest();
    > function sendRequest(t, f)
    > {
    >
    > var myurl = 'nextpage.asp?filepath=' +
    > document.getElementById("myfile").value + '&f=' + f + '&t=';
    >
    > myRand = parseInt(Math.random()*999999999999999);
    > var modurl = myurl + t + "&rand=" + myRand;
    > http.open("GET", modurl, true);
    > http.onreadystatechange = handleResponse;
    > http.send(null);
    > }
    >
    > Does this make senses ?
    > in nextpage.asp, we called for request.querystring("filepath") ?
    >
    > But how should the ENCTYPE="multipart/form-data" being included in
    > this case? or is there others ?
    >
    > any thoughts?
    >



    Your concept seems somewhat confused. A GET has no entity body and
    therefore no content type. Do you have it in mind for nextpage to post the
    file? That isn't going to work, the browser won't send a file in a form
    unless the user has personally selected the file in that form.

    The only time you might get any (very minimal) millage out of emulating the
    file upload in this way is if you have client side script generating the
    content. E.g..:-

    var sBoundary = '----------78625344'

    var sContent = sBoundary + '\r\n'
    sContent += 'Content-Disposition: form-data; name="datFile";
    filename="C:\\Temp\\Test.txt"\r\n'
    sContent += 'Content-Type: text/plain\r\n\r\n'
    sContent += 'Hello World!\r\n'
    sContent += sBoundary + '--\r\n'

    var xhr = getXMLHTTPRequest();

    xhr.open("POST", "test2.asp?function=fetch", false)
    xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" +
    sBoundary)
    xhr.send(sContent)

    This code mimics the uploading of test.txt file containing "Hello World!".

    I don't think this is what you are after and for security reasons what I
    think you want to do the browser isn't going to let you.


    --
    Anthony Jones - MVP ASP/ASP.NET
    Anthony Jones, Feb 11, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cam

    ASPSmartUpload Question

    cam, Jan 12, 2004, in forum: ASP General
    Replies:
    3
    Views:
    237
    Aaron Bertrand - MVP
    Jan 12, 2004
  2. Jake
    Replies:
    2
    Views:
    613
  3. Jake

    aspSmartupload problem

    Jake, Jun 20, 2004, in forum: ASP General
    Replies:
    0
    Views:
    216
  4. SayMyName

    AspSmartUpload only works half the time

    SayMyName, May 4, 2005, in forum: ASP General
    Replies:
    1
    Views:
    202
    Kyle Peterson
    May 4, 2005
  5. aspSmartUpload Download Problem

    , Jun 6, 2007, in forum: ASP General
    Replies:
    4
    Views:
    258
Loading...

Share This Page