Hi
1. I try upload a file to b4j server. file can upload but why the page is refreshing every time. Could i stop refreshing page when i click the submit button ?
2. cloud i assigned a filename in FileUploaded ? following code is save as a tempfile name.
html code
B4j code
1. I try upload a file to b4j server. file can upload but why the page is refreshing every time. Could i stop refreshing page when i click the submit button ?
2. cloud i assigned a filename in FileUploaded ? following code is save as a tempfile name.
html code
B4X:
<div class="form-group">
<label for="inputEmail">公司Logo檔(max size 100kb)</label>
<form id="uploadfileform" action="filehelper" method="post" enctype="multipart/form-data" >
<div class="form-inline">
<div class="col-sm-10">
<input type="file" name="uploadfileform" id="logo1">
</div>
<input type="submit" name="submit" value="Upload">
</div>
</form>
</div>
B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
'get the callback module from the session (multiple modules can use this handler)
Dim callback As Object = req.GetSession.GetAttribute("file_upload_sender")
Try
Dim data As Map = req.GetMultipartData(File.Combine(File.DirApp, "files"), 100000)
CallSubDelayed2(callback, "FileUploaded", data)
Catch
CallSubDelayed2(callback, "FileError", LastException.Message)
resp.SendError(500, LastException.Message)
End Try
End Sub
Public Sub FileUploaded(parts As Map)
Dim filePart As Part = parts.Get("uploadfileform")
Dim s1 As String="File uploaded successfully: " & filePart.SubmittedFilename & _
" size = " & NumberFormat(File.Size("", filePart.TempFile) / 1000, 0, 0) & "kb"
WebUtils.bsAlert(bsalert,s1)
' File.Delete("", filePart.TempFile)
'ws.Flush 'this is a server event so we need to explicitly call Flush
End Sub