HTTPSocket Download

  1. If I put this URL:

https://resources.eveonline.com/88/88d1e1c4e2128b2d_a67ce4a01b440ee1551724e8836b0591
into a browser I get a downloaded PNG file named 88d1e1c4e2128b2d_a67ce4a01b440ee1551724e8836b0591 without the extension.

  1. Adding an extension (in this case .png) to the file name allows me to open the file as a png and view the picture as it is intended to be seen.

  2. If I use httpSocket to download this same file with the following code:

Dim http As New HTTPSocket Dim f as FolderItem = SpecialFolder.Desktop.Child("resDLData.png") http.Get(lblItem02.Text, f)
(where lblItem02.Text contains the URL from item 1 above for the file I want to grab)

3) The file downloads as expected with the name ‘resDLData.png’ and is found on the Desktop as expected.

  1. Attempts to open the file results in the following message:

“It may be damaged or use a file format that Preview doesn’t recognize.”

5) Preview’s default file format is .png so it should open right up

  1. Comparing the two files (the one from item 2 and the one from item 3) with a hex editor reveals that there is extra data at the beginning and end of the ‘damaged’ file which isn’t there on the ‘undamaged’ file.

[code]DAMAGED FILE BEGINNING

=============ASCII===================
( pS 88d1e1c4e2128b2d_a67ce4a01b
440ee1551724e8836b0591 Y@ PNG
IHDR >a pHYs
==============HEX====================
1F8B080828EA705302FF383864316531633465323132386232645F61363763653461303162
3434306565313535313732346538383336623035393100005940A6BF89504E470D0A1A0A00
00000D4948445200000080000000800806000000C33E61CB000000097048597300000B1300

UN-DAMAGED FILE BEGINNING

=============ASCII===================
PNG IHDR >a
pHYs
==============HEX====================
89504E470D0A1A0A0000000D4948445200000080000000800806000000C33E61CB00000009
7048597300000B1300
[/code]

  1. The damaged file actually has the name of the downloaded file in that extra data leading me to believe that a header of some sort remains on the downloaded file.

What am I forgetting/doing wrong? Shouldn’t the file downloaded using HTTPSocket match the file downloaded manually?

OS X 10.12.5
Xojo 2017 r1.1

The PNG has probably been compressed with gzip; 1F 8B if the gzip magic number.

Actually… if you’re using the code above as is, there’s a couple of issues:

  • the socket goes out of scope before it can finish because you’re calling Get asynchronously but storing the socket locally. Either define that property elsewhere or add a 3rd parameter with a timeout value.
  • you’re not handling 302 Redirect messsges from the server, so if that URL isn’t the actual location, all you’ll get back is a 302 status with a location header telling you where to look next.

gzip compression was the answer here.

1 - Instead of naming the downloaded file ‘resDLData.png’ I named the file ‘resDLData.gzip’.
2 - Unzipping ‘resDLData.gzip’ produces the file ‘88d1e1c4e2128b2d_a67ce4a01b440ee1551724e8836b0591’
3 - Add the .png extension to the resulting file
4 - File opens as expected in Preview

HT to Andrew Lambert

Greg - Thank you, and I will certainly take your information under advisement for later upgrades to the code.