You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xamarin.Auth AddMultipartData调用Strava上传接口失败,数据未发送原因排查

Troubleshooting Strava Upload Failure with Xamarin.Auth

Let's break down why your upload request is failing with that confusing error response, even though you're using the correct file parameter as per Strava's documentation.

The Root Problem

Looking closely at your code, there's a critical variable mismatch in your multipart data setup:

FileStream fs = new FileStream(fileName, FileMode.Open);
var request = new OAuth2Request("POST", new Uri("https://www.strava.com/api/v3/uploads"), null, StravaAccount);
// You're passing 'input' here, but you opened the file stream into 'fs'
request.AddMultipartData("file", input, "application/gpx+xml", Uri.EscapeDataString(fileName));

You initialized a FileStream named fs pointing to your GPX file, but when calling AddMultipartData, you're passing a variable called input instead of fs. This means you're not actually sending any file content to Strava—hence the (misleading) "empty data" error they're returning.

Fixed Code

Replace input with fs in the AddMultipartData call, and use a using block to properly dispose the stream (best practice to avoid resource leaks):

using (FileStream fs = new FileStream(fileName, FileMode.Open))
{
    var request = new OAuth2Request("POST", new Uri("https://www.strava.com/api/v3/uploads"), null, StravaAccount);
    request.AddMultipartData("file", fs, "application/gpx+xml", Uri.EscapeDataString(fileName));
    Response response = await request.GetResponseAsync();
}

Quick Additional Checks

  • Confirm fileName points to a valid, non-empty GPX file on your device.
  • Make sure your StravaAccount has the required write scope (mandatory for upload operations).
  • Double-check the MIME type matches your file format (application/gpx+xml is correct for GPX files; adjust if you're using TCX/FIT).

内容的提问来源于stack exchange,提问作者Chris

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:35:27