Android Question Upload files/image from my B4A app to IIS server over the internet

Calvin Yee

Member
Licensed User
I want to upload image from my B4A APP to IIS server over the internet or wifi.

I using code below:-
Private link As String = "https:\\web.abc.com.my\abcweb\Temp" =>This is IIS server setting
Private cc As ContentChooser

Sub btnSendFile_Click
cc.Show("*/*", "Choose file")
End Sub

Sub cc_Result (Success As Boolean, Dir As String, FileName As String)
If Success Then
Dim j As HttpJob
Dim out As OutputStream
out.InitializeToBytesArray(0)
Dim In As InputStream = File.OpenInput(Dir, FileName)
File.Copy2(In, out)

Dim lastSlash As Int = FileName.LastIndexOf("/")
If lastSlash > -1 Then
FileName = FileName.SubString(lastSlash + 1)
End If
Dim su As StringUtils
Dim j As HttpJob
j.Initialize("file", Me)
j.PostBytes(link & "?type=file&name=" & su.EncodeUrl(FileName, "UTF8"), _
out.ToBytesArray)
End If
End Sub

I obtain the following error with file attach.

Any suggestion to fix this problem?
Thanks a Lot to everyone.
Best regards.
 

Attachments

  • upload_error.PNG
    upload_error.PNG
    64 KB · Views: 148

DonManfred

Expert
Licensed User
Longtime User
1. Please use [CODE]code here...[/CODE] tags when posting code.
2. Post errors as TEXT
3. Use okhttputils2 instead of httputils.
4. Usually one need to use PostMultiPart for a Fileupload.

Examplecode

B4X:
Dim j As HttpJob
    j.Initialize("", Me)
    Dim m As Map = CreateMap("additionalfield":"additional data")
   
    Dim filelist As List  ' List holding all files to Upload
    filelist.Initialize
   
    Dim fd As MultipartFileData ' Create a MultipartFileData for each file to upload
    fd.Initialize
    fd.Dir = File.DirAssets
    fd.FileName = "testfiletoupload.txt"
    fd.ContentType = "Text/Plain"
    fd.KeyName = "Testfile"
   
    filelist.Add(fd) ' and add the MultipartFileData to the list
   
    j.PostMultipart("http://domain.com/uploadendpoint.php",m,filelist) ' Upload the files and also giving the additional Values (m Map) to the uploadendpoint
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    End If
    j.Release
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top