1

IMPORT_MESSAGES_ERROR: files collection is empty ... when import .wln

Topic: IMPORT_MESSAGES_ERROR: files collection is empty ... when import .wln

Hi, I am using VB.NET to import a zip file with messages  and I get this error:

{"error":4, "reason":"IMPORT_MESSAGES_ERROR: files collection is empty"}

Here is my code:

unitID is the unit id, and filePathis the full path to zip file.

Dim s As HttpWebRequest
Dim boundary As String = "----WebKitFormBoundary" + DateTime.Now.Ticks.ToString("x")
Dim urlx As String = Wialon_WS_URL + "?svc=exchange/import_messages&sid=" + WialonID
s = HttpWebRequest.Create(urlx)
s.Method = "POST"
s.ContentType = "multipart/form-data; boundary=" + boundary
s.Accept = "Accept-Encoding: gzip,deflate,sdch"
s.KeepAlive = True
s.AllowWriteStreamBuffering = True
Dim memStream As Stream = New MemoryStream()
Dim boundarybytes = Encoding.ASCII.GetBytes(vbCrLf & "--" & boundary & vbCrLf)
Dim endBoundaryBytes = Encoding.ASCII.GetBytes(vbCrLf & "--" & boundary & "--")
Dim formdataTemplate As String = vbCrLf & "--" & boundary & vbCrLf & "Content-Disposition: form-data; name=""{0}""" & vbCrLf & vbCrLf & "{1}"

Dim formitem As String = String.Format(formdataTemplate, "params", "{""itemId"":" + unitID + ",""eventHash"":""jUploadForm1372773585167""}")
Dim formitembytes As Byte() = Encoding.UTF8.GetBytes(formitem)
memStream.Write(formitembytes, 0, formitembytes.Length)

Dim formitem2 As String = String.Format(formdataTemplate, "eventHash", "jUploadForm1372773585167")
Dim formitembytes2 As Byte() = Encoding.UTF8.GetBytes(formitem2)
memStream.Write(formitembytes2, 0, formitembytes2.Length)

Dim headerTemplate As String = "Content-Disposition: form-data; name=""{0}""; filename=""{1}""" & vbCrLf & "Content-Type: application/x-zip-compressed" & vbCrLf & vbCrLf
memStream.Write(boundarybytes, 0, boundarybytes.Length)
Dim header = String.Format(headerTemplate, "messages_filter_import_file", Path.GetFileName(filePath))
Dim headerbytes = Encoding.UTF8.GetBytes(header)
memStream.Write(headerbytes, 0, headerbytes.Length)
Using fileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
    Dim buffer = New Byte(1023) {}
    Dim bytesRead As Integer = 0
    While (fileStream.Read(buffer, 0, buffer.Length) <> 0)
        memStream.Write(buffer, 0, bytesRead)
    End While
End Using
memStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length)
s.ContentLength = memStream.Length
Dim requestStream As Stream = s.GetRequestStream()
memStream.Position = 0
Dim tempBuffer() As Byte = New Byte((memStream.Length) - 1) {}
memStream.Read(tempBuffer, 0, tempBuffer.Length)
memStream.Close()
requestStream.Write(tempBuffer, 0, tempBuffer.Length)

Dim Respuesta_JSON As String = ""
Dim response As HttpWebResponse = DirectCast(s.GetResponse(), HttpWebResponse)
Dim stream2 As Stream = response.GetResponseStream()
Dim reader2 As StreamReader = New StreamReader(stream2)
Respuesta_JSON = reader2.ReadToEnd()

I really appreciate your help!

2

IMPORT_MESSAGES_ERROR: files collection is empty ... when import .wln

Re: IMPORT_MESSAGES_ERROR: files collection is empty ... when import .wln

Hello!

Can you please attach original file with messages (or send it to PM) . it seems like there is not correct format, or broken files, or may be messages with expired history date.

Diana Cheley
Wialon Hosting Expert
Gurtam
3

IMPORT_MESSAGES_ERROR: files collection is empty ... when import .wln

(edited by sergio.botta 30/04/2020 15:02:02)

Re: IMPORT_MESSAGES_ERROR: files collection is empty ... when import .wln

Hi Diana!
This is the zip file I want to send.
Thank you.

Post's attachments

Attachment icon ZIPFILE.zip 251 b, 119 downloads since 2020-04-30 

4

IMPORT_MESSAGES_ERROR: files collection is empty ... when import .wln

Re: IMPORT_MESSAGES_ERROR: files collection is empty ... when import .wln

sergio.botta wrote:

This is the zip file I want to send.

Hello. File looks valid.

Sorry, but I don't know Visual Basic and cannot debug it. I can suggest to use any traffic sniffer and inspect request of manual import from wialon and compare it with your request. It should help to investigate, what causes this issue.

5

IMPORT_MESSAGES_ERROR: files collection is empty ... when import .wln

Re: IMPORT_MESSAGES_ERROR: files collection is empty ... when import .wln

chdi Thank you for your response. chdi , can you help me with VB code? Thanks to all!

6

IMPORT_MESSAGES_ERROR: files collection is empty ... when import .wln

Re: IMPORT_MESSAGES_ERROR: files collection is empty ... when import .wln

sergio.botta wrote:

chdi Thank you for your response. chdi , can you help me with VB code? Thanks to all!

Hello!

as my collegue wrote, unfortunatley, we cannot help you with Visual Basic debug. The file is ok, succefully imported to Wialon system by JS,  so maybe some problems in variables in your code.

Diana Cheley
Wialon Hosting Expert
Gurtam