Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > aspSmartUpload and Ajax

Reply
Thread Tools

aspSmartUpload and Ajax

 
 
magix8@gmail.com
Guest
Posts: n/a
 
      02-11-2008
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
 
Reply With Quote
 
 
 
 
Anthony Jones
Guest
Posts: n/a
 
      02-11-2008

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
aspSmartUpload Download Problem david@davesaconsulting.com ASP General 4 06-08-2007 01:20 PM
AspSmartUpload only works half the time SayMyName ASP General 1 05-04-2005 04:54 PM
aspSmartupload problem Jake ASP General 0 06-20-2004 08:29 PM
aspSmartUpload.SmartUpload doesnt save my file? Jake ASP General 2 06-05-2004 02:14 PM
ASPSmartUpload Question cam ASP General 3 01-12-2004 08:31 PM



Advertisments