cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

The Hub is now in read-only mode as we make improvements to the Hub experience. More information is available here.

Uploading activities via API: How to flag commute and trainer

Digar04
Shkhara

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)\r\n")
    bodyData.append("Content-Disposition: form-data; name=\"file\"; filename=\"\(file.url.lastPathComponent)\"\r\n")
    bodyData.append("Content-Type: application/\(fileType)\r\n\r\n")    
  (...)

    // Append sporttype
    bodyData.append("\r\n--\(boundary)\r\n")
    bodyData.append("Content-Disposition: form-data; name=\"sport_type\"\r\n\r\n")
    bodyData.append("\(file.sportType)\r\n")
 
    // Append name
    bodyData.append("\r\n--\(boundary)\r\n")
    bodyData.append("Content-Disposition: form-data; name=\"name\"\r\n\r\n")
    bodyData.append("\(file.name)\r\n")
 
    // Append description
    bodyData.append("\r\n--\(boundary)\r\n")
    bodyData.append("Content-Disposition: form-data; name=\"description\"\r\n\r\n")
    bodyData.append("\(file.description)\r\n")
    
// Append trainer
    bodyData.append("\r\n--\(boundary)\r\n")
    bodyData.append("Content-Disposition: form-data; name=\"trainer\"\r\n\r\n")
    bodyData.append("\(file.trainer ? "1" : "0")\r\n") // Convert Bool to "1" or "0"
 
    // Append commute
    bodyData.append("\r\n--\(boundary)\r\n")
    bodyData.append("Content-Disposition: form-data; name=\"commute\"\r\n\r\n")
    bodyData.append("\(file.commute ? "1" : "0")\r\n") // Convert Bool to "1" or "0
 
    // Append data type parameter
    bodyData.append("\r\n--\(boundary)\r\n")
    bodyData.append("Content-Disposition: form-data; name=\"data_type\"\r\n\r\n")
    bodyData.append("\(fileType)\r\n")
 
    bodyData.append("--\(boundary)--\r\n")


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
 

4 REPLIES 4

Digar04
Shkhara

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!

Jan_Mantau
Superuser
Superuser

<deleted>

How do you add those properties to the URL?

Digar04
Shkhara

Any idea?