Android Question Add image to webservice parameters list.

Paolo Pini

Member
Licensed User
Longtime User
I need to send a set of parameters to a webserver,
I am trying to use Download2 in this way:

B4X:
j.Download2("https://api.site/service", Array As String("par1", "PAR1", "par2", "PAR2", "Key", "11111111"))
the problem is that I also have to send an image along with the parameters, so the instruction should be:

B4X:
j.Download2("https://api.site/service", Array As String("par1", "PAR1", "par2", "PAR2", "Key", "11111111", "img",<image jpg>))
How can I add the image to the parameter list?

Thank you

Paolo


Translated with DeepL.com (free version)
 

DonManfred

Expert
Licensed User
Longtime User
How can I add the image to the parameter list?
send a multipartpost-request.

You can not build such LONG "URLs in a GET-request. It will simply just not work. The amount is limited in the url....

But it all depends on the destination and how the accept the data. Without showing the documentation it is really hard to give a congrete answer.
 
Upvote 0

Paolo Pini

Member
Licensed User
Longtime User
send a multipartpost-request.

You can not build such LONG "URLs in a GET-request. It will simply just not work. The amount is limited in the url....

But it all depends on the destination and how the accept the data. Without showing the documentation it is really hard to give a congrete answer.
Many thanks for your reply.

I modified my script after looking to some example on lan:

B4X:
    Dim ApiKey As String="111111111111111111111"
    Dim service As String="service"
    Dim location As String="location"
    Dim Url As String="https://api.service.com/service"
    Dim job As HttpJob
    Dim fd As MultipartFileData
       
    job.Initialize("UploadHTTP_File", Me)
   
    fd.Initialize
    fd.KeyName = "file"
    fd.Dir = File.DirAssets
    fd.FileName = "car.png"
    fd.ContentType = "image/png"
   
    Dim Img As List
    Img.Initialize
    Img.Add(fd)
   
    Dim m As Map
   
    m.Initialize
   
    m.Put("location", location)
    m.Put("service", service)
    m.Put("Api-Key", ApiKey)
    'm.Put("image", Img)
   
    job.PostMultipart(Url, m, Img)
 
    Wait For (job) JobDone(job As HttpJob)
   
    If job.Success Then
        Log(job.GetString)
    Else
        Log("ERROR")
    End If

(parameters are hidden)

I only see that JobDone fails, how can I see wich is the return error?

Thanks in advance

Paolo
 
Upvote 0

Paolo Pini

Member
Licensed User
Longtime User
But it all depends on the destination and how the accept the data. Without showing the documentation it is really hard to give a congrete answer.
Thanks for your reply,

I agree with you but I would first like to understand if I am using the right syntax, e.g. is the parameter name 'image' included in the variable Img?

Paolo
 
Upvote 0
Top