PDA

View Full Version : How to restrict download size in AJAX request?



msuresh
20 Jan 2011, 6:25 AM
Hi,

Is it possible to restrict download size in AJAX request?

I have a situation where few log files are huge, if downloaded will crash the browser. In case the size increases above 1 Mb, I need to stop downloading and display whatever has been downloaded and display an alert message.

Is it possible in ExtJS to do this? Any help is appreciated.

Regards,
Suresh

20 Jan 2011, 6:41 AM
Hi,

Is it possible to restrict download size in AJAX request?

I have a situation where few log files are huge, if downloaded will crash the browser. In case the size increases above 1 Mb, I need to stop downloading and display whatever has been downloaded and display an alert message.

Is it possible in ExtJS to do this? Any help is appreciated.

Regards,
Suresh

no. your server will have to do this.

20 Jan 2011, 6:42 AM
a 1mb ajax request should not be an issue for the browser. Perhaps your VIEW is the problem.

valititi
20 Jan 2011, 7:15 AM
ONLY for IE you can use :


var yourFileToSubmit= new ActiveXObject("Scripting.FileSystemObject");
with this you can have all the file details BEFORE sumbit...
then,

var thefile = oas.getFile(document.yourForm.yourfileField.value;);
var filesize = thefile.size;
alert(Math.ceil(f/1024) + "kb...");but, you see, this is not pure javascript :-)
can this help ?

20 Jan 2011, 7:24 AM
ONLY for IE you can use :


var yourFileToSubmit= new ActiveXObject("Scripting.FileSystemObject");
with this you can have all the file details BEFORE sumbit...
then,

var thefile = oas.getFile(document.yourForm.yourfileField.value;);
var filesize = thefile.size;
alert(Math.ceil(f/1024) + "kb...");but, you see, this is not pure javascript :-)
can this help ?



How does this help down stream ajax requests?!?

valititi
20 Jan 2011, 7:30 AM
by checking the filesize before the ajax call and

if (more than needed simply)
--> not make any Ajax !
else,
--> if his filesize is ok then made Ajax call and submit the file to the server

his problem seem to be how to know if the user submit a too big flle...
whatever, like you says 1Mb is not a problem for any browser... but... if he needs this, as a limit...

20 Jan 2011, 7:32 AM
by checking the filesize before the ajax call and

if (more than needed simply)
--> not make any Ajax !
else,
--> if his filesize is ok then made Ajax call and submit the file to the server

He's not asking to UPLOAD a file! He's talking about restricting how much data can be DOWNLOADED via AJAX. <face palm>.

mschwartz
20 Jan 2011, 7:33 AM
http://www.lostrepublic.us/Graphics/DoubleFacePalm.jpg

20 Jan 2011, 7:34 AM
Can i be the dude on the right?

mschwartz
20 Jan 2011, 7:34 AM
Make it so, number one.

valititi
20 Jan 2011, 7:38 AM
heuh... ok. i go too far ! :-) you have right ! i was already on the client side. yes, you cannot check, because simply you don't know how big it WILL be... ok :-)
but then you can fix a limit size on server, then check filesize asked by the Ajax call and only return an error message (instead sending content file) if size depass the needed size ...

mschwartz
20 Jan 2011, 7:40 AM
From the client, you can Ext.Ajax.request() and ask the server, "how big is the file?"

Or you can loop on the client and Ext.Ajax.request() and ask the server, "send me the next 1MB"

valititi
21 Jan 2011, 10:48 PM
hey msuresh (http://www.sencha.com/forum/member.php?18904-msuresh) ?
we had "disputed" here to giving you a solution... But if is not yet enough for you, I can ask Jay and David to comeback for some extra-rounds... :-))

msuresh
1 Feb 2011, 7:14 AM
Sorry valititi, I was looking at the thread closely. I know it is quite difficult to get a solution for my problem, any how I just wanted to cross check.

Anyway thanks for your thoughts