I have larger mp4 files to upload from devices to my server.
I have been using "PostFile", which does work but seems to take considerable time when uploading (say) a 20 meg file (over cell or wifi).
Now I am trying to test speed difference with PostMultipart - get nothing but failure.
( Failed Postfile: 20190306_112004.mp4 msg: java.net.SocketException: sendto failed: EPIPE (Broken pipe) )
I see many example to send the file - but nothing on how to receive it on the server... (EXCEPT for PHP examples - Thanks Don...).
B4A code:
B4J Server side:
ABM uses PostMultiPart - which I have used well, yet he handles the processing, for the most part...
Thanks
I have been using "PostFile", which does work but seems to take considerable time when uploading (say) a 20 meg file (over cell or wifi).
Now I am trying to test speed difference with PostMultipart - get nothing but failure.
( Failed Postfile: 20190306_112004.mp4 msg: java.net.SocketException: sendto failed: EPIPE (Broken pipe) )
I see many example to send the file - but nothing on how to receive it on the server... (EXCEPT for PHP examples - Thanks Don...).
B4A code:
B4X:
Sub SendPostFile(dir As String, filename As String)
Dim st, en As Long = 0
CallSubDelayed(Main,"SetLargeFile") ' show a label that upload has started
Sleep(500) ' need delay to make label show
st = DateTime.Now
Dim j As HttpJob
j.Initialize( "", Me)
' Note: this works - with much time to complete...
' j.PostFile(Starter.srvlinkins & "?type=file&name=" & su.EncodeUrl( filename, "UTF8") , dir, filename)
' Now - try and substitute Multipart...
Dim fd As MultipartFileData
fd.Initialize
fd.KeyName = "file"
fd.Dir = dir
fd.FileName = filename
fd.ContentType = "application/octet-stream"
j.PostMultipart(Starter.srvlinkins, CreateMap("name": filename), Array(fd))
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log("Current link: " & Starter.link& " Dir: "&dir&" File: "&filename)
Log(" Success PostFile: "&j.GetString)
ToastMessageShow("Large File Was Sent: "&CRLF&filename, True) ' &" msg: "&j.ErrorMessage,False)
Else
LogColor(" Failed Postfile: "&filename &" msg: "&j.ErrorMessage,Colors.Red)
ToastMessageShow(" Failed Postfile: "&filename &" msg: "&j.ErrorMessage,False)
End If
j.Release
en = DateTime.Now
Log(" it took this time to send: "&(en-st))
CallSubDelayed(Main,"StopMsgLabel") ' hide label when upload has finished
End Sub
B4J Server side:
B4X:
Select reqType
Case "file"
Dim name As String = req.GetParameter("name")
Dim fd As String = File.DirApp &"/"&Main.inspectFolder
File.MakeDir(File.DirApp , Main.inspectFolder)
Dim out As OutputStream = File.OpenOutput( fd, name, False)
File.Copy2(In, out)
out.Close
Log("Postbyte Received : " & name & ", size=" & File.Size(fd, name))
resp.Write(" postbyte saved this file: "&name)
End Select
ABM uses PostMultiPart - which I have used well, yet he handles the processing, for the most part...
B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
Dim data As Map
Dim fileName As String
Dim tmpFileName As String
Try
data = req.GetMultipartData( downloadfolder, MaxSize )
Catch
Log(" Download Error: "&LastException.Message)
End Try
Dim filePart As Part = data.Get("upl")
If filePart.IsInitialized Then
fileName = filePart.SubmittedFilename
tmpFileName = filePart.TempFile
End If
' internally handle this type of upload request with - ABM.HandleUpload
If ABM.HandleUpload( downloadfolder, tmpFileName, fileName) Then
CallSubDelayed3(callback, "Page_FileUploaded", fileName, True)
End If
End Sub
Thanks
Last edited: