What is meant by "Discussions"?
ADODB.Stream 'format error: not a pdf or corrupt' only on large file
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > ASP web-programming > ADODB.Stream 'format error: not a pdf or corrupt' only on large file 15 April 2008 08:35:57

  Recent blog posts: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

ADODB.Stream 'format error: not a pdf or corrupt' only on large file

Iporter 15 April 2008 08:35:57
 I use the code below to authorise the download of certain files.
Thus, instead of linking to the file in a wwwroot directory, I link to
this code with the filename as a parameter, and the script streams the
file if the user is authorised.

This has worked fine on PDFs, DOCs, XLS, etc. until today, and 18MB
file presents the error message 'format error: not a pdf or corrupt'.

Is there a file size limit, or a default that needs overridden? Any
thoughts?

Cheers.


The Code:

<%@ language="javascrip­t"%>
<%
if (Session("UserID") == 0) {
Response.Redirect("­notauthorized.asp");­
} else {
Response.ContentTyp­e = "application/x-unkn­own";
var fn = Request.QueryString­("fn");
// Response.Write(fn);­
// Response.End();
// fn = "ecpa_efficacy_minu­tes_08_11_06.pdf"
var FPath = "E:\\Inetpub\\irac-­online.org\\document­s\\" + fn;
Response.AddHeader(­"Content-Disposition­","attachment; filename=" +
fn);

var adoStream = Server.CreateObject­("ADODB.Stream");
adoStream.Open();
adoStream.Type = 1;
adoStream.LoadFromF­ile(FPath);
Response.BinaryWrit­e(adoStream.Read());­
adoStream.Close();
adoStream = null;

Response.End();
}
%>

Add comment
Dave Anderson 29 March 2007 22:46:04 permanent link ]
 iporter wrote:
I use the code below to authorise the download of certain files.
Thus, instead of linking to the file in a wwwroot directory, I link to
this code with the filename as a parameter, and the script streams the
file if the user is authorised.
This has worked fine on PDFs, DOCs, XLS, etc. until today, and 18MB
file presents the error message 'format error: not a pdf or corrupt'.

What do you mean by "presents the error message"? Is this a client-side
error or a server-side error?

If client-side, then you may need to examine things like your ASP output
buffer size and your script timeouts.

More than likely, you can solve this by writing in chunks. See the example
about halfway down this article:
http://www.aspfaq.c­om/show.asp?id=2161



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.


Add comment
Iporter 30 March 2007 15:07:19 permanent link ]
 On Mar 29, 7:46 pm, "Dave Anderson" <NYRUMTPEL...@spamm­otel.com>
wrote:
iporter wrote:
I use the code below to authorise the download of certain files.
Thus, instead of linking to the file in a wwwroot directory, I link to
this code with the filename as a parameter, and the script streams the
file if the user is authorised.
This has worked fine on PDFs, DOCs, XLS, etc. until today, and 18MB
file presents the error message 'format error: not a pdf or corrupt'.
What do you mean by "presents the error message"? Is this a client-side
error or a server-side error?
If client-side, then you may need to examine things like your ASP output
buffer size and your script timeouts.
More than likely, you can solve this by writing in chunks. See the example
about halfway down this article:http://www.­aspfaq.com/show.asp?­id=2161
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.

Cheers - resolution involved increasing the AspBufferingLimit in
Metabase.xml - see http://clearglass.n­et/index.php?p=10.

Add comment
Anthony Jones 30 March 2007 15:25:42 permanent link ]
 
"iporter" <isporter@gmail.com­> wrote in message
news:1175252838.974­189.131720@o5g2000hs­b.googlegroups.com..­.
On Mar 29, 7:46 pm, "Dave Anderson" <NYRUMTPEL...@spamm­otel.com>
wrote:
iporter wrote:
I use the code below to authorise the download of certain files.
Thus, instead of linking to the file in a wwwroot directory, I link to
this code with the filename as a parameter, and the script streams the
file if the user is authorised.
This has worked fine on PDFs, DOCs, XLS, etc. until today, and 18MB
file presents the error message 'format error: not a pdf or corrupt'.
What do you mean by "presents the error message"? Is this a client-side
error or a server-side error?
If client-side, then you may need to examine things like your ASP output
buffer size and your script timeouts.
More than likely, you can solve this by writing in chunks. See the
example
about halfway down this article:http://www.­aspfaq.com/show.asp?­id=2161
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message.
Use
of this email address implies consent to these terms.
Cheers - resolution involved increasing the AspBufferingLimit in

Here is a port of my VBScript SendFileToResponse function (I haven't tested
this JScript version):-

function SendFileToResponse(­FilePath, FileName)
{
var clChunkSize = 1048576 // 1MB

Response.Buffer = false

Response.ContentTyp­e = "application/octet-­stream"
Response.AddHeader(­"Content-Disposition­",
"attachment; Filename=" + FileName)

var oStream = Server.CreateObject­("ADODB.Stream")
oStream.Type = 1 // Binary
oStream.Open()
oStream.LoadFromFil­e(FilePath)

for (var i = 1, length = Math.floor(oStream.­Size / clChunkSize); i <=
length; i++)
Response.BinaryWrit­e(oStream.Read(clChu­nkSize))

if ((oStream.Size % clChunkSize) <> 0)
Response.BinaryWrit­e(oStream.Read(oStre­am.Size % clChunkSize))
oStream.Close()
}

It has the advantage of using memory more effeciently on the server by
turning off buffering and chunking the file to the response. There is no
need to modify the buffering limit from the default 4MB when using this
function.



Add comment
Dave Anderson 30 March 2007 15:54:41 permanent link ]
 "Anthony Jones" wrote:
It has the advantage of using memory more effeciently on
the server by turning off buffering and chunking the file
to the response.

Is that fact or speculation? I've never seen evidence that this is more
efficient on the server.


There is no need to modify the buffering limit from the
default 4MB when using this function.

Agreed. And this one is undeniable.




--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.

Add comment
Anthony Jones 30 March 2007 16:46:05 permanent link ]
 
"Dave Anderson" <NYRUMTPELVWH@spamm­otel.com> wrote in message
news:130pukgbkev6dd­1@corp.supernews.com­...
"Anthony Jones" wrote:
It has the advantage of using memory more effeciently on
the server by turning off buffering and chunking the file
to the response.
Is that fact or speculation? I've never seen evidence that this is more
efficient on the server.

It's not a fact by observation but neither is it speculation.

Here is a fact:-

Response.BinaryWrit­e doesn't return until all the buffer contents have been
sent.

I'll let you do the math.



Add comment
Dave Anderson 30 March 2007 17:44:07 permanent link ]
 Anthony Jones wrote:
It's not a fact by observation but neither is it speculation.
Response.BinaryWrit­e doesn't return until all the buffer
contents have been sent.

Doesn't return what? From what? To what? This does not make any sense to me.


I'll let you do the math.

OK. In either case, the same amount of content has to be put into the
buffer, and the same amount written from the buffer. You don't even bother
to speculate about the cost of repeatedly using Stream.Read(bytes) over
Stream.Read(adReadA­ll). So absent the Urim and Thummim neccessary for
scrying the Response Object, there does not seem to be any "math" to do. You
are *clearly* speculating.

I will grant this -- when combined with Response.isClientCo­nnected [1],
using the chunked method allows you to abort the process before the entire
Stream is dealt with, which seems at first glance like a decent idea for
sending very large files. But since your example ignores isClientConnected,
you have not made any sort of "performance" case whatsoever.



[1] Is it a method or a property? The documentation calls it a property, buy
shows it as a method. Stranger still, you can treat it as either one in
JScript.
http://msdn.microso­ft.com/library/en-us­/iissdk/html/a07ec44­5-9240-4f23-8fe9-1f9­548d3f8b0.asp

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.


Add comment
Anthony Jones 30 March 2007 19:28:44 permanent link ]
 
"Dave Anderson" <NYRUMTPELVWH@spamm­otel.com> wrote in message
news:%23HBL%23FtcHH­A.4260@TK2MSFTNGP02.­phx.gbl...
Anthony Jones wrote:
It's not a fact by observation but neither is it speculation.
Response.BinaryWrit­e doesn't return until all the buffer
contents have been sent.
Doesn't return what? From what? To what? This does not make any sense to
me.
I'll let you do the math.
OK. In either case, the same amount of content has to be put into the
buffer, and the same amount written from the buffer. You don't even bother
to speculate about the cost of repeatedly using Stream.Read(bytes) over
Stream.Read(adReadA­ll). So absent the Urim and Thummim neccessary for
scrying the Response Object, there does not seem to be any "math" to do.
You
are *clearly* speculating.
I will grant this -- when combined with Response.isClientCo­nnected [1],
using the chunked method allows you to abort the process before the entire
Stream is dealt with, which seems at first glance like a decent idea for
sending very large files. But since your example ignores
isClientConnected,
you have not made any sort of "performance" case whatsoever.

Dave,

My apologies I've seem to have managed to irk you once again.

What I meant by 'sent' is sent and acknowledged by the client.

With a buffered response the entire contents is duplicated in memory at the
same time, once in the array read from the stream and once in the buffer.
How much of the file is also duplicated inside the stream object I'm not
certain possibly all of it.

With the 'unbuffered' response only 1MB of the file is duplicated in memory
at the time plus whatever is in the ADODB stream.

Of course in the buffered solution the stream and the array are released
when the client starts to receive bytes. At this time the script context
will also be torn down. Ultimately the average memory requirement for the
buffered solution is likely to be less than my unbuffered one. This would
depend on details of the ADODB stream internals, how much the script context
uses and how big the file is. However it's peak memory requirements are
significantly more.

Another implementation detail that I don't known is whether IIS releases
some of the buffer whilst still using it. It seems an obvious thing to do
which would mean the buffered technique's average memory usage would be
somewhere approaching half the file size. The slower the link the closer to
half the file size it will be.

OTH the 'unbuffered' solution will keep the ADODB.Stream and therefore
potentially a duplicate of the file in memory for the duration of the send.
Hence it's peak requirement is at worst the file size + 2MB. However that is
also it's average requirement as well.

Overall then in a real world I'm probably wrong. Unless spike memory
requirement of the buffered solution is a problem. Although might I risk
your ire once again I do believe ADODB.Stream uses a .tmp file when mem
usage becomes excessive but I could be wrong ... again.

Anthony.




Add comment
Guest 15 April 2008 08:35:57 permanent link ]
 Hi,

You may try to recover the corrupt pdf file. You may try Advanced PDF Repair at http://www.datanume­n.com/apdfr/ This tool is rather useful in salvaging damaged PDF documents.

Hope this will help.

Alan
Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > ASP web-programming > ADODB.Stream 'format error: not a pdf or corrupt' only on large file 15 April 2008 08:35:57

see also:
ViewSonic LCD monitor
Display goes off...please help me
Belkin Omniview F1DS104P
пройди тесты:
see also:
Status: offline 10 days
My life is perfect!
I'm very angry!

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .