05-16-2021 00:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-16-2021 00:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.

Accepted Solutions
05-16-2021 01:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


05-16-2021 01:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.
Gondwana Software

05-16-2021 01:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


05-16-2021 01:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.
Gondwana Software

07-13-2021 14:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-13-2021 14:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


07-13-2021 14:22
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
@JasonWohaWhat files are you referring to?
Gondwana Software
07-13-2021 14:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-13-2021 14:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Files received from the device through file transfer.

07-13-2021 14:54
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


07-13-2021 14:54
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
In the companion, 'files' are actually received as a variable in memory.
Gondwana Software
07-14-2021 06:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-14-2021 06:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
What are the ways to access those files from an external source?

07-14-2021 13:25
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


07-14-2021 13:25
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Send it to a server using fetch().
Gondwana Software
01-30-2024 16:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-30-2024 16:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


01-30-2024 17:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Did you convert config_data into an ArrayBuffer or ArrayBufferView? See this.
Gondwana Software

01-30-2024 17:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-30-2024 17:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


01-30-2024 17:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@ac_devel wrote:...Would it it be possible to run fetch directly?
Not sure what you mean.
Gondwana Software

01-30-2024 17:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-30-2024 17:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


01-30-2024 18:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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?
Gondwana Software

01-30-2024 20:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-30-2024 20:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
The processing of the queue is done after pushing a button and then I read
it right away.
Is it possible that the file is not available right away?

01-30-2024 20:25
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


01-30-2024 20:25
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Gondwana Software

