Android Question Problem with REST API - Form Data

syerif

Active Member
Licensed User
Longtime User
Hi all,

please help me, i get problem with upload image, my API link using NodeJS, and it required this one



code:
 const image = req.files.image.tempFilePath;

I use multipart data, to pass a request
my question is how to pass it . i do not have idea....

B4A:
Dim imagens As List
    imagens.Initialize

    Dim fd As MultipartFileData
    fd.Initialize
    fd.KeyName = "bawahan1.jpg"
    fd.Dir = File.DirInternal
    fd.FileName = "bawahan1.jpg"
    fd.ContentType = "image/JPEG"
    imagens.Add(fd)
   
    Dim tempFilePath As String = File.DirInternal &"/"& "bawahan1.jpg"
   
    Dim j As HttpJob
    j.Initialize("j", Me)

    Dim postData As Map
    postData.Initialize
    'postData.Put("textinfo","somedata")
    'postData.Put("image",tempFilePath)
    postData.Put("latitude",latitude)
    postData.Put("longitude",longitude)
    postData.Put("kategori",kategori)
    postData.Put("jenis",jenis)
    postData.Put("idTransaksi",idTransaksi)
    postData.Put("nik",nik)
   
    j.PostMultipart(url_absensi,postData,imagens)
    j.GetRequest.SetHeader("Authorization",general.token)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        If j.Response.StatusCode =200 Then
            Dim result As String =j.GetString
            Log(result)
        End If
    Else
        Log(j.ErrorMessage)
    End If
Thanks
 

syerif

Active Member
Licensed User
Longtime User
Hi all,

please help me, i get problem with upload image, my API link using NodeJS, and it required this one



code:
 const image = req.files.image.tempFilePath;

I use multipart data, to pass a request
my question is how to pass it . i do not have idea....

B4A:
Dim imagens As List
    imagens.Initialize

    Dim fd As MultipartFileData
    fd.Initialize
    fd.KeyName = "bawahan1.jpg"
    fd.Dir = File.DirInternal
    fd.FileName = "bawahan1.jpg"
    fd.ContentType = "image/JPEG"
    imagens.Add(fd)
  
    Dim tempFilePath As String = File.DirInternal &"/"& "bawahan1.jpg"
  
    Dim j As HttpJob
    j.Initialize("j", Me)

    Dim postData As Map
    postData.Initialize
    'postData.Put("textinfo","somedata")
    'postData.Put("image",tempFilePath)
    postData.Put("latitude",latitude)
    postData.Put("longitude",longitude)
    postData.Put("kategori",kategori)
    postData.Put("jenis",jenis)
    postData.Put("idTransaksi",idTransaksi)
    postData.Put("nik",nik)
  
    j.PostMultipart(url_absensi,postData,imagens)
    j.GetRequest.SetHeader("Authorization",general.token)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        If j.Response.StatusCode =200 Then
            Dim result As String =j.GetString
            Log(result)
        End If
    Else
        Log(j.ErrorMessage)
    End If
Thanks
 
Upvote 0
Top