Hi everyone,
I am trying to store a file as a binary array in an "image" field in SQL
Server 2000 database.
It works OK except for the ".PDF" files, which I believe get corrupted in
the
process of reading a stream to a byte array.
Uploading and downloading seems to work fine, but "Acrobat" pop ups
"The file is damaged and could not be repaired" error.
Is there any way I can make this to work.
Following is a pseudo code of what I am trying to accomplish.
//Uploading a file browser->web server
//get file size (theFile is a VS "file field" component )
int fileSize = theFile.PostedF ile.ContentLeng th;
//get file as binary stream
Stream fileStream = theFile.PostedF ile.InputStream ;
//create byte array to keep file as bytes
byte[] bArray = new byte[fileSize];
//load array from stream
fileStream.Read (bArray , 0, size);
//At this point bArray is saved to DataBase
//Downloading file
//read image field from database and typecast as byte array
byte [] bArray = GetBinaryArrayF romDB()
string fileName = GetFileName();
string fileType = GetMIMEFileType ();
//Send file to the browser
Response.AddHea der("Content-Disposition", "attachment ; filename=" +
fileName);
Response.Conten tType = fileType;
Response.Binary Write(bArray); 1 5788
Angel Filev wrote: Hi everyone, I am trying to store a file as a binary array in an "image" field in SQL Server 2000 database. It works OK except for the ".PDF" files, which I believe get corrupted in the process of reading a stream to a byte array. Uploading and downloading seems to work fine, but "Acrobat" pop ups "The file is damaged and could not be repaired" error. Is there any way I can make this to work.
Following is a pseudo code of what I am trying to accomplish.
//Uploading a file browser->web server //get file size (theFile is a VS "file field" component ) int fileSize = theFile.PostedF ile.ContentLeng th; //get file as binary stream Stream fileStream = theFile.PostedF ile.InputStream ; //create byte array to keep file as bytes byte[] bArray = new byte[fileSize]; //load array from stream fileStream.Read (bArray , 0, size); //At this point bArray is saved to DataBase
//Downloading file //read image field from database and typecast as byte array byte [] bArray = GetBinaryArrayF romDB() string fileName = GetFileName(); string fileType = GetMIMEFileType ();
//Send file to the browser Response.AddHea der("Content-Disposition", "attachment ; filename=" + fileName); Response.Conten tType = fileType; Response.Binary Write(bArray);
Your not-so-pseudo-code looks ok ;-)
What happens if you set a Content-Length header with the value of
bArray.Length? Older Acrobat plugins require Content-Length.
Cheers,
-- http://www.joergjooss.de
mailto:ne****** **@joergjooss.d e This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jeff |
last post by:
how do you convert form byte to Int32 while retaining the binary
value of the byte array
|
by: Swarup |
last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling
it into a byte arry. Now i have to convert it into a string to store it in
the database.
I use
System.Text.UnicodeEncoding enc = new System.Text.UnicodeEncoding();
now i am using enc.GetString(value) and the value retured is one byte less
if the size of the byte array is Odd. In case of files having even number
of bytes, the convertion is happening correctly and...
|
by: Ricardo Quintanilla |
last post by:
i have a code that sends data to a socket listening over as400 platform,
the socket responds to me as a "byte array".
then i need to convert the "byte array" into a string.
the problem is that the data converted from the byte array into a string
, is not what i expect.
example:
- the data returned from the socket is (byte array)
"Usuario Sin Atribuciones Para Esta Función"
|
by: MuZZy |
last post by:
Hi,
I just wonder if someone can help me wit this -
i have a byte array and need to convert it to short array, creating
short numbers by combining bytes by pairs:
My array: byte, byte, byte, etc.
I need: short = byte+byte, short = byte+byte, etc.
|
by: Kueishiong Tu |
last post by:
How do I convert a Byte array (unsigned char managed) to a
char array(unmanaged) with wide character taken into
account?
| |
by: moondaddy |
last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a
string, and then from a string back to a byte array.
for example
Private mByte() as New Byte(4){11,22,33,44}
Now how do I convert it to:
dim myStr as string = "11,22,33,44"
|
by: Peter |
last post by:
Trying to convert string to byte array.
the following code returns byte array of {107, 62, 194, 139, 64}
how can I convert this string to a byte array of {107, 62, 139, 65}
System.Text.UTF8Encoding str = new System.Text.UTF8Encoding();
string s = new string((char)107, 1);
s += new string((char)62, 1);
|
by: est |
last post by:
From python manual
str( )
Return a string containing a nicely printable representation of an
object. For strings, this returns the string itself. The difference
with repr(object) is that str(object) does not always attempt to
return a string that is acceptable to eval(); its goal is to return a
printable string. If no argument is given, returns the empty string,
''.
|
by: da1978 |
last post by:
Hi experts,
I need to convert a string or a Byte array to a string byte array.
Its relatively easy to convert a string to an char array or a byte array but not a
STRING byte array. i.e.
Dim Array() As Char
Dim strwork As String = "76A3kj9d6"
Array = strwork.ToCharArray
OR
|
by: Debadatta Mishra |
last post by:
Introduction
In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |