By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,384 Members | 801 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,384 IT Pros & Developers. It's quick & easy.

tif file loses integrity when uploaded

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
>>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

P: n/a
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

P: n/a
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

P: n/a
>>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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.