04-06-2022 12:54
04-06-2022 12:54
I am trying tranfer some files using file transfer API.
This is my index.js:
function processAllFiles() {
let fileName;
while (fileName = inbox.nextFile()) {
console.log(`/private/data/${fileName} is now available`);
}
}
inbox.onnewfile = processAllFiles;
This is my settings.js:
inbox.onnewfile = loadSettings;
And this is my weather.js:
inbox.onnewfile = () => {
processWeatherData(fs.readFileSync('weather.cbor', 'cbor'));
};
But for soe reason it only goes to the weather function instead of both settings and weather. Why? How do I fix this?
Thank you.
Best Answer04-07-2022 04:01
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
04-07-2022 04:01
When you assign a function to the event in that way you're essentially replacing the existing handler each time.
Use this instead, but really you only want 1 handler for new files anyway.
inbox.addEventListener('newfile', loadSettings);
inbox.addEventListener('newfile', processAllFiles);
Best Answer