src/main/java/de/blau/android/osm/OsmGpxApi.java
/**
     * Upload a GPS track in GPX format
     * 
     * @param server the Server object for the API instance to use
     * @param track the track
     * @param description optional description
     * @param tags optional tags
     * @param visibility privacy/visibility setting
     * 
     * @throws IOException on an IO error
     */
Upload a GPS track in GPX format



@throws IOException on an IO error
Upload a GPS track in GPX format @throws IOException on an IO error
public static void uploadTrack(@NonNull Server server, @NonNull final Track track, @NonNull String description, @NonNull String tags,
            @NonNull Visibility visibility) throws IOException {
        RequestBody gpxBody = new RequestBody() {
            @Override
            public MediaType contentType() {
                return MediaType.parse(MimeTypes.GPX);
            }
            @Override
            public void writeTo(BufferedSink sink) throws IOException {
                try {
                    track.exportToGPX(sink.outputStream());
                } catch (IllegalArgumentException | IllegalStateException | XmlPullParserException e) {
                    throw new IOException(e);
                }
            }
        };
        String fileNamePart = DateFormatter.getFormattedString(DATE_PATTERN_GPX_TRACK_UPLOAD_SUGGESTED_FILE_NAME_PART);
        RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart(DESCRIPTION_KEY, description)
                .addFormDataPart(TAGS_KEY, tags).addFormDataPart(VISIBILITY_KEY, visibility.name().toLowerCase(Locale.US))
                .addFormDataPart(FILE_KEY, fileNamePart + "." + FileExtensions.GPX, gpxBody).build();
        try (Response response = server.openConnectionForAuthenticatedAccess(getUploadTrackUrl(server), Server.HTTP_POST, requestBody)) {
            if (!response.isSuccessful()) {
                Server.throwOsmServerException(response);
            }
        }
    }
public static void uploadTrack ( @ NonNull Server server , @ NonNull final Track track , @ NonNull String description , @ NonNull String tags , @ NonNull Visibility visibility ) throws IOException { RequestBody gpxBody = new RequestBody ( ) { @ Override public MediaType contentType ( ) { return MediaType . parse ( MimeTypes . GPX ) ; } @ Override public void writeTo ( BufferedSink sink ) throws IOException { try { track . exportToGPX ( sink . outputStream ( ) ) ; } catch ( IllegalArgumentException | IllegalStateException | XmlPullParserException e ) { throw new IOException ( e ) ; } } } ; String fileNamePart = DateFormatter . getFormattedString ( DATE_PATTERN_GPX_TRACK_UPLOAD_SUGGESTED_FILE_NAME_PART ) ; RequestBody requestBody = new MultipartBody . Builder ( ) . setType ( MultipartBody . FORM ) . addFormDataPart ( DESCRIPTION_KEY , description ) . addFormDataPart ( TAGS_KEY , tags ) . addFormDataPart ( VISIBILITY_KEY , visibility . name ( ) . toLowerCase ( Locale . US ) ) . addFormDataPart ( FILE_KEY , fileNamePart + "." + FileExtensions . GPX , gpxBody ) . build ( ) ; try ( Response response = server . openConnectionForAuthenticatedAccess ( getUploadTrackUrl ( server ) , Server . HTTP_POST , requestBody ) ) { if ( ! response . isSuccessful ( ) ) { Server . throwOsmServerException ( response ) ; } } }
Upload a GPS track in GPX format
Upload a GPS track in GPX format