aspSmartUpload and Ajax

M

magix8

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
 
A

Anthony Jones

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top