Skip to main content

Dear all

I'm using SwiftUI code to upload files to Strava's API. Upload is working finde. If I add name and description to my upload body, it is recognized by the API and displayed at my activity dashboard.

However, "commute" (as INT), "trainer" (as INT), or "sport_type" (as STRING) keep being ignored.

Thats part of my code to create the POST request body:

// Append file data to request body
    bodyData.append("--(boundary)

"
)
    bodyData.append("Content-Disposition: form-data; name=""file""; filename=""(file.url.lastPathComponent)""

")
    bodyData.append("Content-Type: application/(fileType)



")    
  (...)

    // Append sporttype
    bodyData.append("

--
(boundary)

"
)
    bodyData.append("Content-Disposition: form-data; name=""sport_type""



")
    bodyData.append("(file.sportType)

"
)
 
    // Append name
    bodyData.append("

--
(boundary)

"
)
    bodyData.append("Content-Disposition: form-data; name=""name""



")
    bodyData.append("(file.name)

"
)
 
    // Append description
    bodyData.append("

--
(boundary)

"
)
    bodyData.append("Content-Disposition: form-data; name=""description""



")
    bodyData.append("(file.description)

"
)
    
// Append trainer
    bodyData.append("

--
(boundary)

"
)
    bodyData.append("Content-Disposition: form-data; name=""trainer""



")
    bodyData.append("(file.trainer ? "1" : "0")

"
) // Convert Bool to "1" or "0"
 
    // Append commute
    bodyData.append("

--
(boundary)

"
)
    bodyData.append("Content-Disposition: form-data; name=""commute""



")
    bodyData.append("(file.commute ? "1" : "0")

"
) // Convert Bool to "1" or "0
 
    // Append data type parameter
    bodyData.append("

--
(boundary)

"
)
    bodyData.append("Content-Disposition: form-data; name=""data_type""



")
    bodyData.append("(fileType)

"
)
 
    bodyData.append("--(boundary)--

"
)


Any idea what's wrong? I've tried different values/typs for commute and trainer, such as 1 or 0, true/True/TRUE or false/False/FALSE, INT or String, but they are still not showing up at my activity dashboard. Same for sport_type... (even if I don't use variables but hard code).

I would really much appreciate if somebody would help!

Thank you!

Ben
 

Any idea?


<deleted>


How do you add those properties to the URL?


I'm still struggeling with adding properties such as sport type, commute, and trainer to my uploads to Strava API. Code is written in SwiftUI. 

Does anyone use SwiftUI code to upload files to Strava API? How do you add add the properties mentioned above to your files? Any held would be highly appreciated!


Reply