Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old November 11th, 2005, 10:51 PM
Al Knowles
Guest
 
Posts: n/a
Default 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.


  #2  
Old November 11th, 2005, 10:51 PM
Oleg Tkachenko
Guest
 
Posts: n/a
Default Re: tif file loses integrity when uploaded

Al Knowles wrote:
[color=blue]
> 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).[/color]
So somebody has screwed up the file along uploading, show us your code.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

  #3  
Old November 11th, 2005, 10:51 PM
Al Knowles
Guest
 
Posts: n/a
Default Re: tif file loses integrity when uploaded

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:uh6vT2eVDHA.2288@TK2MSFTNGP12.phx.gbl...[color=blue]
> Al Knowles wrote:
>[color=green]
> > I have researched and tried every method I can find for passing a[/color][/color]
two-page[color=blue][color=green]
> > 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[/color][/color]
the[color=blue][color=green]
> > 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[/color][/color]
the[color=blue][color=green]
> > image format is not
> > supported. (This is all local development).[/color]
> So somebody has screwed up the file along uploading, show us your code.
> --
> Oleg Tkachenko
> http://www.tkachenko.com/blog
> Multiconn Technologies, Israel
>[/color]


  #4  
Old November 11th, 2005, 10:52 PM
Al Knowles
Guest
 
Posts: n/a
Default Re: tif file loses integrity when uploaded


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!
  #5  
Old November 11th, 2005, 10:52 PM
Al Knowles
Guest
 
Posts: n/a
Default Re: tif file loses integrity when uploaded

>>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.
[color=blue]
>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");[/color]

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:#eXk8kpVDHA.3376@tk2msftngp13.phx.gbl...[color=blue]
> Al Knowles wrote:[color=green]
> > Values passed from vb6 application via xml:
> >
> > iBinStream is the binary file with tags
> > <DOCUMENT><IMAGE>data</IMAGE></DOCUMENT>[/color]
> 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[/color]
binary[color=blue]
> data to text.
>[color=green]
> > 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.[/color]
> Are you sure this function works ok? What's wrong with using standard
> XmlTextWriter.WriteBase64 method instead of some function "found on the[/color]
net"?[color=blue]
>[color=green]
> > The length of the original file (iFileLen) is also provided by the[/color][/color]
client[color=blue][color=green]
> > application.[/color]
> 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 -
>[/color]
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemxmlxmltextreaderclassreadbase64topic.as p[color=blue]
>
> --
> Oleg Tkachenko
> http://www.tkachenko.com/blog
> Multiconn Technologies, Israel
>[/color]




  #6  
Old November 11th, 2005, 10:52 PM
Oleg Tkachenko
Guest
 
Posts: n/a
Default Re: tif file loses integrity when uploaded

Al Knowles wrote:
[color=blue]
> 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?[/color]
Yeah, you right, I missed you are on VB6 on that side.
[color=blue][color=green]
>>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");[/color]
>
>
> 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?[/color]
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

  #7  
Old November 11th, 2005, 10:52 PM
Brad Quinn
Guest
 
Posts: n/a
Default Re: tif file loses integrity when uploaded

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" <brad_quinn@yahoo.com> wrote in message
news:eWwWVG3VDHA.2040@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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[/color]
tweak;[color=blue]
>
> 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[/color]
4" );[color=blue]
> }
> } else {
> bw.Write( Convert.FromBase64String( data ) );
> }
>
> In my case, the "badly" encoded string had too much padding.
>
> Good Luck.
>
> "Al Knowles" <codefinger@cox.net> wrote in message
> news:gawVa.27709$zd4.10821@lakeread02...[color=green]
> > I have researched and tried every method I can find for passing a[/color][/color]
two-page[color=blue][color=green]
> > 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[/color]
> the[color=green]
> > 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[/color]
> the[color=green]
> > image format is not
> > supported. (This is all local development).
> >
> > Does anyone have a tested example of uploading a two-page tif file from[/color][/color]
a[color=blue][color=green]
> > VB6 application to a web service
> > via XML? At this point I don't care how it is done, I just need[/color][/color]
something[color=blue][color=green]
> > that works!
> >
> > Thanks in advance for any assistance you can provide.
> >
> >[/color]
>
>[/color]


  #8  
Old November 11th, 2005, 10:52 PM
Al Knowles
Guest
 
Posts: n/a
Default Re: tif file loses integrity when uploaded

>>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" <brad_quinn@yahoo.com> wrote in message
news:#X4avM3VDHA.2024@TK2MSFTNGP12.phx.gbl...[color=blue]
> 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[/color]
encoding[color=blue]
> in a way that is garaunteed to be compatible. You could then use the COM
> object from VB6.
>
> "Brad Quinn" <brad_quinn@yahoo.com> wrote in message
> news:eWwWVG3VDHA.2040@TK2MSFTNGP11.phx.gbl...[color=green]
> > 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[/color][/color]
/[color=blue][color=green]
> > Base64Decode from the ATL library.
> >
> > When I tried to decode using .NET I found out that the encodings were[/color][/color]
just[color=blue][color=green]
> > slightly incompatible. I was able to correct this with the following[/color]
> tweak;[color=green]
> >
> > 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[/color]
> 4" );[color=green]
> > }
> > } else {
> > bw.Write( Convert.FromBase64String( data ) );
> > }
> >
> > In my case, the "badly" encoded string had too much padding.
> >
> > Good Luck.
> >
> > "Al Knowles" <codefinger@cox.net> wrote in message
> > news:gawVa.27709$zd4.10821@lakeread02...[color=darkred]
> > > I have researched and tried every method I can find for passing a[/color][/color]
> two-page[color=green][color=darkred]
> > > 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[/color][/color][/color]
is[color=blue][color=green]
> > the[color=darkred]
> > > same as the uploaded length.
> > > Double-clicking on the file before it is uploaded will display it in[/color][/color][/color]
an[color=blue][color=green][color=darkred]
> > > image preview application.
> > > Double clicking on the newly uploaded file always returns an error[/color][/color][/color]
that[color=blue][color=green]
> > the[color=darkred]
> > > image format is not
> > > supported. (This is all local development).
> > >
> > > Does anyone have a tested example of uploading a two-page tif file[/color][/color][/color]
from[color=blue]
> a[color=green][color=darkred]
> > > VB6 application to a web service
> > > via XML? At this point I don't care how it is done, I just need[/color][/color]
> something[color=green][color=darkred]
> > > that works!
> > >
> > > Thanks in advance for any assistance you can provide.
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


  #9  
Old November 11th, 2005, 10:52 PM
Al Knowles
Guest
 
Posts: n/a
Default Re: tif file loses integrity when uploaded

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" <codefinger@cox.net> wrote in message
news:upcuNHRWDHA.2352@TK2MSFTNGP12.phx.gbl...[color=blue]
> 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![/color]


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles