BrotherEarth
Member
I have written a simple response to return the text of a file to the system requesting it. The text file is simple json and it works fine. However, I also need to send a zip file. The requirements do not allow me to send it via FTP, I have to send it via websocket, I am using AsyncStreams. I have reviewed the tutorials and read many threads, but I am having no luck.
The zip file transfers fine, but it is' invalid', it will not open with winzip or gzip, even though the size from the original to the host are the same file size. I looked at the contents of each file, and after the first few bytes, they are different. So there is a conversion/corruption happening.
I suppose I need to work with the bytes of the zip file, not as text?
Has anyone done this before, or does anyone have some suggestions?
The zip file transfers fine, but it is' invalid', it will not open with winzip or gzip, even though the size from the original to the host are the same file size. I looked at the contents of each file, and after the first few bytes, they are different. So there is a conversion/corruption happening.
I suppose I need to work with the bytes of the zip file, not as text?
Has anyone done this before, or does anyone have some suggestions?
B4A Code:
If File.Exists(filePath, fileName) Then
If fileName = "config.json" Then
tempstr = File.ReadString(filePath, fileName)
Log(File.Size(filePath, fileName))
Dim strResponse As String = "HTTP/1.1 200 OK" & CRLF & _
"Content-Type: text/html; charset=utf-8" & CRLF & _
"Content-Transfer-Encoding: gzip" & CRLF & _
"Content-Length: " & File.Size(filePath, fileName) & CRLF & _
"X-File-Name: " & deviceId & "_" & fileName & CRLF & _
CRLF & tempstr
Return strResponse
Else If fileName.Contains(".zip") Then
tempstr = File.ReadString(filePath, fileName)
Dim strResponse As String = "HTTP/1.1 200 OK" & CRLF & _
"Content-Type: application/zip; charset=IS8859-1" & CRLF & _
"Content-Length: " & File.Size(filePath, fileName) & CRLF & _
"X-File-Name: " & deviceId & "_" & fileName & CRLF & _
"Content-Disposition: attachment; filename=" & fileName & CRLF & _
CRLF & tempstr
Return strResponse
End If
Return "HTTP/1.1 404 NOT FOUND"
Else
Return "HTTP/1.1 404 NOT FOUND"
End If