basvandorst / StravaPHP

Strava API REST client with OAuth authentication
MIT License
184 stars 67 forks source link

Upload gpx file failed #74

Closed patricktann closed 3 years ago

patricktann commented 3 years ago

$client->uploadActivity( '/var/www/466928184.gpx, 'ride', null, null, null, null, null, 'gpx', 466928184 );

failed with the following error:

[SERVICE] [SERVICE] Client error: POST https://www.strava.com/api/v3/uploads?activity_type=ride&data_type=gpx&external_id=466928184&file%5Bname%5D=%2Fvar%2Fwww%2F466928184.gpx&file%5Bmime%5D=&file%5Bpostname%5D=&file_hack=%40%2Fvar%2Fwww%2F466928184.gpx&access_token=*** resulted in a 400 Bad Request response: {"message":"Bad Request","errors":[{"resource":"Upload","field":"file","code":"not a file"}]}

Whats wrong?

patricktann commented 3 years ago

Solution in funtion uploadActivity in src/Strava/API/Service/REST.php:

$parameters['query'] = [ 'activity_type' => $activity_type, 'name' => $name, 'description' => $description, 'private' => $private, 'trainer' => $trainer, 'commute' => $commute, 'data_type' => $data_type, 'external_id' => $external_id, 'file' => curl_file_create($file), 'file_hack' => '@' . ltrim($file, '@'), 'access_token' => $this->getToken(), ];

change into:

$parameters['query'] = [ 'activity_type' => $activity_type, 'name' => $name, 'description' => $description, 'private' => $private, 'trainer' => $trainer, 'commute' => $commute, 'data_type' => $data_type, 'external_id' => $external_id, 'access_token' => $this->getToken(), ]; $parameters['multipart'] = [[ 'name' => 'file', 'contents' => Psr7\Utils::tryFopen($file, 'r') ]];