strava_flutter icon indicating copy to clipboard operation
strava_flutter copied to clipboard

Error on Upload GPX File

Open Numanshakir opened this issue 7 months ago • 4 comments

/// Generates a Strava-compatible GPX file from provided data Future<File> generateStravaCompatibleGpxFile({ required String activityName, required String creator, required List<GpxPoint> points, String activityType = 'running', // match tag DateTime? metadataTime, }) async { StringBuffer buffer = StringBuffer();

// GPX XML Header with required namespaces and schema
buffer.writeln('<?xml version="1.0" encoding="UTF-8"?>');
buffer.writeln(
  '<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 '
  'http://www.topografix.com/GPX/1/1/gpx.xsd" '
  'creator="$creator" version="1.1" xmlns="http://www.topografix.com/GPX/1/1">',
);

// Metadata
final metaTime = metadataTime ?? (points.isNotEmpty ? points.first.time : DateTime.now());
final metaTimeStr = metaTime.toUtc().toIso8601String().replaceFirst(RegExp(r'\.\d+'), '') + 'Z';
buffer.writeln('  <metadata>');
buffer.writeln('    <time>$metaTimeStr</time>');
buffer.writeln('  </metadata>');

// Track
buffer.writeln('  <trk>');
buffer.writeln('    <name>$activityName</name>'); // Use activityName here
buffer.writeln('    <type>$activityType</type>');
buffer.writeln('    <trkseg>');

for (final point in points) {
  // CRITICAL FIX: Include time and elevation (if available) for each track point
  final timeStr = point.time.toUtc().toIso8601String().replaceFirst(RegExp(r'\.\d+'), '') + 'Z';
  buffer.writeln('      <trkpt lat="${point.latitude}" lon="${point.longitude}">');
  if (point.elevation != null) {
    buffer.writeln('        <ele>${point.elevation}</ele>');
  }
  buffer.writeln('        <time>$timeStr</time>');
  buffer.writeln('      </trkpt>');
}

buffer.writeln('    </trkseg>');
buffer.writeln('  </trk>');
buffer.writeln('</gpx>');

// Write to temporary file
final dir = await getTemporaryDirectory();
final file = File('${dir.path}/runflo_${DateTime.now().millisecondsSinceEpoch}.gpx');
await file.writeAsString(buffer.toString());
log("Generated GPX Content:\n${buffer.toString()}"); // Keep this for debugging
return file;

}

this is my model class GpxPoint { final double latitude; final double longitude; final double? elevation; // optional final DateTime time;

GpxPoint({ required this.latitude, required this.longitude, required this.time, this.elevation, }); }

Every time i upload api response is 200 but error message is "Error Processing Data" "There was an error processing your activity."

Numanshakir avatar Jun 01 '25 04:06 Numanshakir

I resolve this issue by using the sample file
}
///this is testing file data
Future<File> createStravaGpxFile() async {
  const gpxContent = '''<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" creator="StravaGPX" version="1.1" xmlns="http://www.topografix.com/GPX/1/1">
 <metadata>
  <time>2025-05-20T22:51:11Z</time>
 </metadata>
 <trk>
  <name>Evening Run</name>
  <type>running</type>
  <trkseg>
   <trkpt lat="39.7218600" lon="-75.5700410">
    <ele>2.1</ele>
    <time>2025-05-20T22:51:11Z</time>
   </trkpt>
   <trkpt lat="39.7218630" lon="-75.5700240">
    <ele>2.1</ele>
    <time>2025-05-20T22:51:12Z</time>
   </trkpt>
   <trkpt lat="39.7218650" lon="-75.5700060">
    <ele>2.1</ele>
    <time>2025-05-20T22:51:13Z</time>
   </trkpt>
   <trkpt lat="39.7218700" lon="-75.5699640">
    <ele>2.1</ele>
    <time>2025-05-20T22:51:14Z</time>
   </trkpt>
   <trkpt lat="39.7218710" lon="-75.5699480">
    <ele>2.1</ele>
    <time>2025-05-20T22:51:15Z</time>
   </trkpt>
   <trkpt lat="39.7218790" lon="-75.5698980">
    <ele>2.1</ele>
    <time>2025-05-20T22:51:16Z</time>
   </trkpt>
   <trkpt lat="39.7218820" lon="-75.5698790">
    <ele>2.1</ele>
    <time>2025-05-20T22:51:17Z</time>
   </trkpt>
   <trkpt lat="39.7218890" lon="-75.5698430">
    <ele>2.1</ele>
    <time>2025-05-20T22:51:18Z</time>
   </trkpt>
   <trkpt lat="39.7218950" lon="-75.5698070">
    <ele>2.1</ele>
    <time>2025-05-20T22:51:19Z</time>
   </trkpt>
  </trkseg>
 </trk>
</gpx>''';

  final dir = await getTemporaryDirectory();
  final file = File('${dir.path}/strava_sample.gpx');
  await file.writeAsString(gpxContent);

  return file;
}

 

Numanshakir avatar Jun 01 '25 05:06 Numanshakir

Hi Numan! Can you please explain more about the issue?

serdarcsk avatar Jun 02 '25 08:06 serdarcsk

Hi. I was trying to upload gpx with my dynamic content but every time showing error Unable to process the activity.

Then i create a manual acticity and download the file and use format

On Mon, 2 Jun 2025, 13:30 serdarcsk, @.***> wrote:

serdarcsk left a comment (dreampowder/strava_flutter#117) https://github.com/dreampowder/strava_flutter/issues/117#issuecomment-2929417432

Hi Numan! Can you please explain more about the issue?

— Reply to this email directly, view it on GitHub https://github.com/dreampowder/strava_flutter/issues/117#issuecomment-2929417432, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP6QJPRVAPDME6JY2LAGUHT3BQDRVAVCNFSM6AAAAAB6KUTEH6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSMRZGQYTONBTGI . You are receiving this because you authored the thread.Message ID: @.***>

Numanshakir avatar Jun 02 '25 08:06 Numanshakir

No need to change on the package . Error was due to content of gpx file

On Mon, 2 Jun 2025, 13:37 Numan Shakir, @.***> wrote:

Hi. I was trying to upload gpx with my dynamic content but every time showing error Unable to process the activity.

Then i create a manual acticity and download the file and use format

On Mon, 2 Jun 2025, 13:30 serdarcsk, @.***> wrote:

serdarcsk left a comment (dreampowder/strava_flutter#117) https://github.com/dreampowder/strava_flutter/issues/117#issuecomment-2929417432

Hi Numan! Can you please explain more about the issue?

— Reply to this email directly, view it on GitHub https://github.com/dreampowder/strava_flutter/issues/117#issuecomment-2929417432, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP6QJPRVAPDME6JY2LAGUHT3BQDRVAVCNFSM6AAAAAB6KUTEH6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSMRZGQYTONBTGI . You are receiving this because you authored the thread.Message ID: @.***>

Numanshakir avatar Jun 02 '25 08:06 Numanshakir