05-16-2021 00:44
05-16-2021 00:44
I am trying to send a text file to a companion(simulator) from device(simulator).
With the sample code in "https://dev.fitbit.com/build/guides/communications/file-transfer/", the companion only reads the contents of file via console.log.
When I try to import "fs" in compaion, I got error that "cannot resolve fs".
Is there an example code to save the file in folder related to the companion?
Answered! Go to the Best Answer.
05-16-2021 01:21
05-16-2021 01:21
fs is device-only.
The companion uses file-transfer.
This isn't sufficient to save the file into an accessible folder. For that, you'll need to use fetch() with a web server.
05-16-2021 01:21
05-16-2021 01:21
fs is device-only.
The companion uses file-transfer.
This isn't sufficient to save the file into an accessible folder. For that, you'll need to use fetch() with a web server.
07-13-2021 14:09
07-13-2021 14:09
Does the companion store the files received from the devices locally? Or it uploads it to the cloud automatically. And the developer needs to query them using the Web API?
07-13-2021 14:22
07-13-2021 14:22
@JasonWohaWhat files are you referring to?
07-13-2021 14:24
07-13-2021 14:24
Files received from the device through file transfer.
07-13-2021 14:54
07-13-2021 14:54
In the companion, 'files' are actually received as a variable in memory.
07-14-2021 06:09
07-14-2021 06:09
What are the ways to access those files from an external source?
07-14-2021 13:25
07-14-2021 13:25
Send it to a server using fetch().
01-30-2024 16:37
01-30-2024 16:37
Related to this topic .. I have a file that I get using fetch from aws. I am trying to send that data to my device but I get
[4:31:12 PM] Companion: Failed to queue session_config.json: TypeError: Failed to execute 'enqueue' on 'FileTransferOutbox': The value provided as parameter 2 is not a valid buffer source (companion/index.js:82,7)
my code is this:
console.log('Enqueue file to device');
outbox.enqueue(config_fname, config_data)
.then((ft) => {
console.log(`Transfer of ${ft.name} successfully queued.`);
})
.catch((error) => {
console.log(`Failed to queue ${config_fname}: ${error}`);
})
where config_data is what I get from my fetch. What am I missing?
01-30-2024 17:00
01-30-2024 17:00
Did you convert config_data into an ArrayBuffer or ArrayBufferView? See this.
01-30-2024 17:30
01-30-2024 17:30
@Gondwana ah! I missed that part. I was trying JSON.stringify thinking it was enough. I'll check it out.
Would it it be possible to run fetch directly?
01-30-2024 17:34
01-30-2024 17:34
@ac_devel wrote:...Would it it be possible to run fetch directly?
Not sure what you mean.
01-30-2024 17:46
01-30-2024 17:46
so I ran fetch on companion app and I was wondering if I can run the same thing on the watch directy.
going back to the transfer, I was able to transfer the file but when I try to read it using
fs.readFileSync(configFilename)
I get
App: Unhandled exception: Error: Couldn't find file: undefined
01-30-2024 18:08
01-30-2024 18:08
No, the fetch API only exists in the companion. The watch doesn't have direct access to networking.
Where did you get configFilename from? When are you trying to read the file?
01-30-2024 20:12
01-30-2024 20:12
01-30-2024 20:25
01-30-2024 20:25