Android Question HTTPJob -

Hello, I'm new to the b4A tool but I'm gaining experience quickly
I have a problem with an HTTPJob postMultipart
I can correctly build the entire request, but the server responds to me

ResponseError. Reason: , Response: {"message":"file.not_found","error":"There is no file in request.","status":400,"cause":[]}

B4X:
If isCustomPic = True Then 'Publica con las fotos que tomó
        If File.Exists(imgFolder, $"${thisPubPictures(1)}.jpg"$) = True Then
            For imgs = 1 To 1 'cnt
                prgML.Progress = 80 + imgs
                Log($"prgML.Progress = "${80 + imgs}"$)
                Dim JobImg As HttpJob
                Dim itmFile  As MultipartFileData
                itmFile.Initialize
                itmFile.Dir = imgFolder        ' General.AppFolder
                itmFile.FileName = $"${thisPubPictures(imgs)}.jpg"$    '"Discogs.json"  '
                itmFile.KeyName =  thisPubPictures(imgs)
                itmFile.ContentType = "image/jpeg"        ' "application/json"
                
                JobImg.Initialize("", Me)               
                JobImg.PostMultipart("https://api.mercadolibre.com/pictures/items/upload", Null, Array(itmFile))
                JobImg.GetRequest.SetHeader("Authorization", $"Bearer ${access_token}"$)               
                
                Wait For (JobImg) jobDone (Jres As HttpJob)
                If Jres.Success = False Then
                    Log(Jres.ErrorMessage)
                    prgML.Progress = 100
                Else
                    Log(Jres.GetString)
                End If
            Next
        End If
    End If

Any other POST or GET requests you make to the same server complete successfully.
The server does not seem to see the request files It is clear of course that the files exist in the indicated path and have access by the application (since they are photos that the application itself took)
I also tried with other files and other folders, and the message is the same
Any suggestion? Thank you very much
 

DonManfred

Expert
Licensed User
Longtime User
Based on the docu
B4X:
curl -H 'Authorization: Bearer $ACCESS_TOKEN' -X POST  \
-H 'content-type: multipart/form-data' \
-F 'file=@/Users/Documents/test.jpg' \
'https://api.mercadolibre.com/pictures/items/upload'
itmFile.KeyName = thisPubPictures(imgs)
the keyname must be "file". Is thisPubPictures(imgs) = "file"? Guess no.

Change it to
B4X:
itmFile.KeyName =  "file"
 
Upvote 0
Thanks to both of you, it indeed works with your suggestions
Now this is the response:
{
"crop":
{
"x_offset": null,
"x_size": null,
"y_offset": null,
"y_size": null
},
"dominant_color": null,
"id": "788347-MLA52368175775_112022",
"max_size": "1200x1200",
"status": "ACTIVE",
"variations":
[
{
"secure_url": "https://http2.mlstatic.com/D_NQ_NP_788347-MLA52368175775_112022-F.jpg",
"size": "1200x1200",
"url": "http://http2.mlstatic.com/D_NQ_NP_788347-MLA52368175775_112022-F.jpg"
},
...


My programming experience is different, I'm just discovering APIs and Web Services
Thank you very much! Greetings from Buenos Aires, Argentina
 
Upvote 0
Top