Skip to content

Commit

Permalink
Merge pull request #42 from tihawk/master
Browse files Browse the repository at this point in the history
fix: activity upload
  • Loading branch information
Pythe1337N authored Mar 14, 2023
2 parents 9898f14 + cc89fcc commit 2c62f55
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/garmin/GarminConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,21 @@ export default class GarminConnect {
*/
async uploadActivity(file: string, format: UploadFileType) {
const detectedFormat = (format || path.extname(file))?.toLowerCase();
const filename = path.basename(file);

if ((<any>Object).values(UploadFileType).includes(detectedFormat)) {
return Promise.reject();
}

const fileBinary = fs.createReadStream(file);
const fileBuffer = fs.readFileSync(file);
const response = this.client.post(urls.upload(format), {
file: fileBinary
userfile: {
value: fileBuffer,
options: {
filename
}
}
});
fileBinary.close();
return response;
}

Expand Down

0 comments on commit 2c62f55

Please sign in to comment.