06-06-2019 09:39 AM
Hello,
I am having trouble opening a JPG file that I download from internet using datasocket.
Please refer to the attached code.
the function seems to work with some files but not other.
I am providing 3 url as an example. the first two will work but the last one fails everytime:
http://media.digikey.com/Renders/Samsung%20Electro-Mechanics%20America/0805-(1.40)-CL-Series.jpg
http://media.digikey.com/Photos/CnC%20Tech/3220-10-0100-00.JPG
http://media.digikey.com/Photos/JST%20Photos/SM05B-PASS-TBT(LF)(SN).JPG
The windows image viewer can view the image saved on file ( but paint also fails to open the file )
I am wondering if the file is somehow being saved corrupt in some cases.
I appreciate any help on this
thanks
AJ
06-06-2019 09:46 AM
Addional note :
one difference between the files that work and the ones that does not is the size of the JPEG.. file
the ones that are working are <50KB of size while the one that failed is 257KB.
06-06-2019 12:17 PM
When I download the file and save it to my desktop, the Read JPEG is able to read it just fine.
06-06-2019 01:06 PM
I am not sure I understand what you mean by download the JPG. did you manually download it wia a web browser or usign the datasocket code I attached ?
the problem might be coming from the datasocket read function . the function outputs a string that I save as a binary file then read it with the open JPG function. this works with small sized images but not with relatively larger files...
06-06-2019 01:44 PM
Of course I downloaded it. You said you had a problem with the downloaded JPEG file.
The JPEG file is just fine.
06-06-2019 02:02 PM
thank you for clarifying.
Do you think this method of downloading an image using datasocket makes sense:
06-07-2019 12:36 AM
The smaller files might work because they are read in a single call of Datasocket Read, whereas the larger JPG might require more than one read. You need to change your string output tunnel on the For Loop to index and then concatenate that string array otherwise you won't read the whole file. Secondly you can't terminate on the first successful read - you need to terminate on the timeout.
06-07-2019 03:25 AM
@mam1nej wrote:
thank you for clarifying.
Do you think this method of downloading an image using datasocket makes sense:
Of course not! The [text] specifier at the end of the datasocket url tells the datasocket function that you are downloading a text file. That tells datasocket also that you want to have different transformations applied to the binary data stream such as EOL conversion from whatever LF, CR, CRLF combination inside the stream to the current platform, which under Windows is CRLF. jpg being highly binary is very sensitive to any bit change in the binary data stream.
Remove that appendix and things should look much better (and a binary compare of the two files will certainly show differences).
06-07-2019 07:58 AM
thanks for the feedback.
I was using the [text] to avoid getting error 42 on datasocket read, as described here
http://digital.ni.com/public.nsf/allkb/27272FE3A32C334286257612004D9153
the datasocket read throws a 42 error if I use the URL without the [text] identifier