473,322 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

tif file loses integrity when uploaded

I have researched and tried every method I can find for passing a two-page
tif file from a VB6 application to
a web service via XML. These include XMLTextReader.ReadBase64,
Convert.FromBase64, and using
the Binary Writer. When the web service stores the file, the length is the
same as the uploaded length.
Double-clicking on the file before it is uploaded will display it in an
image preview application.
Double clicking on the newly uploaded file always returns an error that the
image format is not
supported. (This is all local development).

Does anyone have a tested example of uploading a two-page tif file from a
VB6 application to a web service
via XML? At this point I don't care how it is done, I just need something
that works!

Thanks in advance for any assistance you can provide.
Nov 11 '05 #1
8 2766
Al Knowles wrote:
I have researched and tried every method I can find for passing a two-page
tif file from a VB6 application to
a web service via XML. These include XMLTextReader.ReadBase64,
Convert.FromBase64, and using
the Binary Writer. When the web service stores the file, the length is the
same as the uploaded length.
Double-clicking on the file before it is uploaded will display it in an
image preview application.
Double clicking on the newly uploaded file always returns an error that the
image format is not
supported. (This is all local development).

So somebody has screwed up the file along uploading, show us your code.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
Values passed from vb6 application via xml:

iBinStream is the binary file with tags
<DOCUMENT><IMAGE>data</IMAGE></DOCUMENT>

A function I found on the net called ReadBinData decodes
the file into a base64 encoded string. That is what is placed
between the IMAGE tags.

The length of the original file (iFileLen) is also provided by the client
application.
-----------------------------------------------------

Dim xmlreader As System.Xml.XmlTextReader = _
New System.Xml.XmlTextReader(New
System.IO.StringReader(iBinStream))

xmlreader.MoveToContent()
xmlreader.Read()
lfilelen = CLng(iFileLen)

Dim fs_new(iFileLen) As Byte

xmlreader.ReadBase64(fs_new, 0, iFileLen)

Dim newfile As New _
System.IO.FileStream(fs_new_file_name,
System.IO.FileMode.CreateNew, _
System.IO.FileAccess.Write)

newfile.Write(fs_new, 0, iFileLen)

newfile.Close()
xResult.Stored = True
xResult.Message = fs_new_file_name + " was stored."
xResult.NewfileName = fs_new_file_name
Return xResult
"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:uh**************@TK2MSFTNGP12.phx.gbl...
Al Knowles wrote:
I have researched and tried every method I can find for passing a two-page tif file from a VB6 application to
a web service via XML. These include XMLTextReader.ReadBase64,
Convert.FromBase64, and using
the Binary Writer. When the web service stores the file, the length is the same as the uploaded length.
Double-clicking on the file before it is uploaded will display it in an
image preview application.
Double clicking on the newly uploaded file always returns an error that the image format is not
supported. (This is all local development).

So somebody has screwed up the file along uploading, show us your code.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #3

Provided code, still seeking help.

Begin Begging...
I know you're very busy, but you are the only one who has at least
answered. I've been working on this problem for a week, and you're
supposed to be an expert.
...End Begging

Thanks again for any assistance you can provide.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 11 '05 #4
>>Are you sure this function works ok? What's wrong with using standard
XmlTextWriter.WriteBase64 method instead of some function "found on the
net"?<<

Believe me, I would LOVE to use the XMLTextWriter.WriteBase64 method, but,
AFAIK, that's not available to a VB6 application. Or did I miss something?

Remember, the file is being uploaded from a VB6 application to a .NET web
service.
Have you tried...
int base64len = 0;
byte[] base64 = new byte[1000];
do {
base64len = reader.ReadBase64(base64, 0, 50);
//write base64len bytes from base64 array to the file
} while (reader.Name == "IMAGE");
Now that's an interesting idea, and one I had not thought of.

But where and how did you and the MSDN example decide on a value of 1000 for
the base64 byte array? That's the part that really confuses me. What if the
file length is more than 1000? There's no part of either code that I see
that decides that value. It seems to be arbitrary.
Or am I still missing something?

I'll try out this approach and let you know. Thanks!


"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:#e**************@tk2msftngp13.phx.gbl... Al Knowles wrote:
Values passed from vb6 application via xml:

iBinStream is the binary file with tags
<DOCUMENT><IMAGE>data</IMAGE></DOCUMENT> What do you mean "binary file with tags"? XML document is not binary by
definition, that's the only reason of using Base64 enoding - to encode

binary data to text.
A function I found on the net called ReadBinData decodes
the file into a base64 encoded string. That is what is placed
between the IMAGE tags. Are you sure this function works ok? What's wrong with using standard
XmlTextWriter.WriteBase64 method instead of some function "found on the

net"?
The length of the original file (iFileLen) is also provided by the client application. I'm not sure about it. Have you tried

int base64len = 0;
byte[] base64 = new byte[1000];
do {
base64len = reader.ReadBase64(base64, 0, 50);
//write base64len bytes from base64 array to the file
} while (reader.Name == "IMAGE");

just as in example at MSDN -

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemxmlxmltextreaderclassreadbase64topic.as p
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel



Nov 11 '05 #5
Al Knowles wrote:
Believe me, I would LOVE to use the XMLTextWriter.WriteBase64 method, but,
AFAIK, that's not available to a VB6 application. Or did I miss something?

Yeah, you right, I missed you are on VB6 on that side.
int base64len = 0;
byte[] base64 = new byte[1000];
do {
base64len = reader.ReadBase64(base64, 0, 50);
//write base64len bytes from base64 array to the file
} while (reader.Name == "IMAGE");

Now that's an interesting idea, and one I had not thought of.

But where and how did you and the MSDN example decide on a value of 1000 for
the base64 byte array? That's the part that really confuses me. What if the
file length is more than 1000? There's no part of either code that I see
that decides that value. It seems to be arbitrary.
Or am I still missing something?

1000 is arbitrary, you right. byte[] base64 in the example above is just a
temporary buffer to write decoded stream to. It's usual pattern of buffered
reading of potentially large streams - you are allocating buffer and trying to
read buffer.Length bytes from the stream. Read operation typically returns
number of actually readed bytes - you are using this number of bytes in the
buffer and then repeat reading again and again.

Actually above MSDN example seems to be a bit weird, because they allocate
1000 bytes array, but read by 50 bytes instead of 1000 available. Probably
copy-n-paste typo.

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #6
I'm stuck using this workaround, because I don't control the client.

Does your client have the .NET runtime installed? If it does, I would
create a COM object using .NET (C#, VB, whatever) to do the Base64 encoding
in a way that is garaunteed to be compatible. You could then use the COM
object from VB6.

"Brad Quinn" <br********@yahoo.com> wrote in message
news:eW**************@TK2MSFTNGP11.phx.gbl...
I'm using a "legacy" (can't find the source) COM object to do base64
encoding and decoding. I was pretty sure that it was using Base64Encode /
Base64Decode from the ATL library.

When I tried to decode using .NET I found out that the encodings were just
slightly incompatible. I was able to correct this with the following tweak;
int len = data.Length;
int excess = len % 4;
if ( excess != 0 ) {
if ( data.EndsWith( new string( '=', excess ) ) ) {
bw.Write( Convert.FromBase64String( data.Substring( 0, len -
excess ) ) );
} else {
throw new FormatException( "Base64 string length not a mutiple of 4" ); }
} else {
bw.Write( Convert.FromBase64String( data ) );
}

In my case, the "badly" encoded string had too much padding.

Good Luck.

"Al Knowles" <co********@cox.net> wrote in message
news:gawVa.27709$zd4.10821@lakeread02...
I have researched and tried every method I can find for passing a two-page tif file from a VB6 application to
a web service via XML. These include XMLTextReader.ReadBase64,
Convert.FromBase64, and using
the Binary Writer. When the web service stores the file, the length is

the
same as the uploaded length.
Double-clicking on the file before it is uploaded will display it in an
image preview application.
Double clicking on the newly uploaded file always returns an error that

the
image format is not
supported. (This is all local development).

Does anyone have a tested example of uploading a two-page tif file from a VB6 application to a web service
via XML? At this point I don't care how it is done, I just need something that works!

Thanks in advance for any assistance you can provide.


Nov 11 '05 #7
>>I'm stuck using this workaround, because I don't control the client.<<

Kinda the same problem here. The whole point of using a web service was
supposed to be to avoid the dll hell involved with distributing com objects
to hundreds of machines.

"Brad Quinn" <br********@yahoo.com> wrote in message
news:#X**************@TK2MSFTNGP12.phx.gbl...
I'm stuck using this workaround, because I don't control the client.

Does your client have the .NET runtime installed? If it does, I would
create a COM object using .NET (C#, VB, whatever) to do the Base64 encoding in a way that is garaunteed to be compatible. You could then use the COM
object from VB6.

"Brad Quinn" <br********@yahoo.com> wrote in message
news:eW**************@TK2MSFTNGP11.phx.gbl...
I'm using a "legacy" (can't find the source) COM object to do base64
encoding and decoding. I was pretty sure that it was using Base64Encode /
Base64Decode from the ATL library.

When I tried to decode using .NET I found out that the encodings were just slightly incompatible. I was able to correct this with the following tweak;

int len = data.Length;
int excess = len % 4;
if ( excess != 0 ) {
if ( data.EndsWith( new string( '=', excess ) ) ) {
bw.Write( Convert.FromBase64String( data.Substring( 0, len -
excess ) ) );
} else {
throw new FormatException( "Base64 string length not a mutiple of

4" );
}
} else {
bw.Write( Convert.FromBase64String( data ) );
}

In my case, the "badly" encoded string had too much padding.

Good Luck.

"Al Knowles" <co********@cox.net> wrote in message
news:gawVa.27709$zd4.10821@lakeread02...
I have researched and tried every method I can find for passing a two-page tif file from a VB6 application to
a web service via XML. These include XMLTextReader.ReadBase64,
Convert.FromBase64, and using
the Binary Writer. When the web service stores the file, the length is the
same as the uploaded length.
Double-clicking on the file before it is uploaded will display it in
an image preview application.
Double clicking on the newly uploaded file always returns an error
that the
image format is not
supported. (This is all local development).

Does anyone have a tested example of uploading a two-page tif file

from a VB6 application to a web service
via XML? At this point I don't care how it is done, I just need something that works!

Thanks in advance for any assistance you can provide.



Nov 11 '05 #8
The other developer just told me he was completely wrong about the line
feeds. He's not sure why/how the file loses integrity, but that has nothing
to do with it.
"Al Knowles" <co********@cox.net> wrote in message
news:up**************@TK2MSFTNGP12.phx.gbl...
Another (more experienced) developer has now been assigned to what
should have been a fairly simple task -- to upload an image file from a
VB6 application to a VB.Net WebService and to download an image file
from that web service to the VB6 application.

He has also spent days attempting this without success.

He did discover that the original file, when decoded, includes a line
feed at every 73 character. When the file arrives at the web service
via xmlhttp.send( parms), those line feeds are missing, causing the
resulting string to be smaller than the original.

Is this a bug im xmlhttp.send? A bug in the web service?

Two of us on it, days of research and man hours wasted, and
we still can't accomplish it.

Any hints and or additional suggestions and particularly,
TESTED sample code would be GREATLY appreciated.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 11 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: PeterB | last post by:
Hi! I'm using Pure ASP File Upload (http://www.asp101.com/articles/jacob/scriptupload.asp) to upload a file from a client to a server. I am testing both on a local IIS and a remote server. The...
60
by: Julie | last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB) for a given string. The files are unindexed and unsorted, and for the purposes of my immediate requirements, can't...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
0
by: Benjamin Bittner | last post by:
Hallo NG, ive searched a lot in some google groups, and found many threads, but nothing that helped me. Here is the scenario: I have an aspx page which loads a user control in page.onInit like...
9
by: Arsen V. | last post by:
Hello, What is the suggested way to store uploaded files? 1) IMAGE type data in an SQL Database table 2) As a file in the NTFS file system Thanks, Arsen
1
by: theburnetts | last post by:
I am building an ASP.NET application that has a requirement that the user should be able to download all of the data that they have input into the system and save it to a file on their local PC. ...
5
by: Dylan Parry | last post by:
Hi, I'm trying to upload some files via a form, and I have managed so far to save the files on the server in a temporary directory using: HttpPostedFile.SaveAs(string filename); This is a...
5
by: Russell Warren | last post by:
I've got a case where I'm seeing text files that are either all null characters, or are trailed with nulls due to interrupted file access resulting from an electrical power interruption on the...
5
by: djhexx | last post by:
Hello. I have an ASP.NET application (C#) that I allow users to upload files. Files get stored in a SQL2005 database. The file data is stored in a varbinary(max) column. When the user uploads...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.