iOS Question PostMultipart data error

Lisa I

Member
Licensed User
Hi
I'm working on an application to upload activities (tcx files) to Strava.

My application successfully handles the OAuth2 process - I'm able to request activities, etc, successfully.

However, when I try to upload an activity - it fails.
This is what Strava is asking for
$ curl -X POST https://www.strava.com/api/v3/uploads \
-H "Authorization: Bearer 1234xxxxxxxxx" \
-F activity_type=ride \
-F [email protected] \
-F data_type=fit

Parameters
activity_type: string optional, case insensitive
name: string optional
data_type: string required, case insensitive
possible values: fit, fit.gz, tcx, tcx.gz, gpx, gpx.gz
file: multipart/form-data required, case insensitive

Here's the relevant sample of my code:
B4X:
Dim j As HttpJob
    j.Initialize("", Me)
 
    Dim fd As MultipartFileData
    fd.Initialize
    fd.Dir = File.DirAssets
    fd.FileName = "08052019080800.tcx"
    fd.KeyName = Null 
    fd.ContentType = "text/xml"

    Log("Exists: " & File.Exists   (fd.Dir, fd.FileName))' check the file is there, it is
 
    j.PostMultipart("https://www.strava.com/api/v3/uploads", CreateMap("activity_type": "ride","name": "08052019080800", "data_type": "tcx"), Array(fd))
 
    'header needed for authorization
    Dim bearer As String = "Bearer " & newtoken
    Log ("header = " & bearer) 
    j.GetRequest.SetHeader("Authorization", bearer)
 
       
    Wait For (j) JobDone(j As HttpJob)
    j.GetString
    Log("waiting for job done " & j.GetString)
    If j.Success Then
     
        Log("success")
    Else
     
        Log(j.ErrorMessage)
    End If

Any ideas what I'm doing wrong? I get error ResponseError: unknown error, status code: 400

Thank you
Lisa
 

Lisa I

Member
Licensed User
Hi Erel

I have ported the code onto B4A and get more of an error message than with B4i.
It seems like the header is not getting through with the PostMultipart command.

I haven't seen any other examples using a header with postmultipart in the forum, is this not possible to do with j.GetRequest.SetHeader?


ResponseError. Reason: , Response: {"message":"Authorization Error","errors":[{"resource":"AccessToken","field":"activity:write_permission","code":"missing"}]}

Thanks
 
Upvote 0
Top