• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image File is getting damaged after read from the sqlserver database

 
Levi Mendes
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I need create a file from a sqlserver database whose the field is text, when I create the image from the String value or byte[], the image is getting damaged, I dont know the reason, can anyone help me please?
Have you understood?

Are there any error on my code?

My picture is getting so:



My code:



Regardless, thanks.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when I create the image from the String value

Images are binary data, so if you ever store them in a string, or use Readers or Writers for them, the data is corrupted (unless you took precautions to make it not so, like base-64 encoding them, but it doesn't sound like you did).
 
Levi Mendes
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ulf Dittmer
,

Images are binary data, so if you ever store them in a string, or use Readers or Writers for them, the data is corrupted (unless you took precautions to make it not so, like base-64 encoding them, but it doesn't sound like you did).



There are a system that use this database, the system was designed in Visual Fox Pro, the system read the images that are stored on this database. Yesterday one developer shown me the code that he uses to read the images, he uses a method called StrToFile to create the File from the image (a file with jpg extension), now I dont know what to do, on Visual Fox Pro he gets read the image with no problem, in Java when I try read it Im getting so:


One man said to me yestarday the samethins you said me:
the data is corrupted
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know someone -even in your company, it sounds like- who is successful doing this, shouldn't you be talking to him, and have him explain to you the details of how it works?
 
Levi Mendes
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer

I talked with him yesterday, the process he uses is the following:
Process to insert the image on database:
To insert the image on database exists one button that open a input dialog to the user select the image, the system read the image and convert it to string through a method called FileToString, that is all, according to him.
Process to read the image:
The programmer makes a select on database: "select pic from tb", the select command returns a string, then he calls a method called StrToFile, now he gets an image file with no problem.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what do those FileToString and StrToFile methods do? Obviously, your code will have to do the same to the data.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic