11-18-2018 05:53 - edited 11-18-2018 05:54
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-18-2018 05:53 - edited 11-18-2018 05:54
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hello all,
i want to fetch a file from internet.
For testing I use the following code:
// Import Outbox from the file-transfer module
import { outbox } from "file-transfer"
// Source image on the internet
let srcImage = "https://placekitten.com/348/250";
// Destination filename
let destFilename = "kitten.jpg";
// Fetch the image from the internet
fetch(srcImage).then(function (response) {
// We need an arrayBuffer of the file contents
return response.arrayBuffer();
}).then(function (data) {
// Queue the file for transfer
outbox.enqueue(destFilename, data).then(function (ft) {
// Queued successfully
console.log("Transfer of '" + destFilename + "' successfully queued.");
}).catch(function (error) {
// Failed to queue
throw new Error("Failed to queue '" + destFilename + "'. Error: " + error);
});
}).catch(function (error) {
// Log the error
console.log("Failure: " + error);
});
I get the following error: Unhandled ReferenceError: fetch is not defined
If I define fetch like that:
let fetch = "";
I get the following error: Unhandled TypeError: Expected a function.
How to get an File from Internet (on Fitbit Simulator) ?
Cheers,
NoWo
Answered! Go to the Best Answer.

Accepted Solutions
11-23-2018 09:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-23-2018 09:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
You're confusing code which must be run in the companion, not on the device. fetch() is companion only.
11-18-2018 11:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-18-2018 11:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
If you're using typescript (as opposed to straight javascript), I think this can happen. There may be an import or something that defines fetch in this situation.
Gondwana Software

11-19-2018 04:02
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-19-2018 04:02
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi Catplace,
i don´t use typescript, only Fitbit Studio and Fitbit Simulator.
It has to be possible, many Apps/Clocks can get Data from Internet, I think they use fetch, but when I use fetch I get the these errors 😕

11-23-2018 09:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-23-2018 09:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
You're confusing code which must be run in the companion, not on the device. fetch() is companion only.
11-26-2018 14:05
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-26-2018 14:05
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hi JonFitbit, I get it done 🙂
As I think to use the companion-Part there must be an actice connection to Smartphone.
But now I´m wondering because the Ionic has WiFi connection but needs connection to the Smartphone, which itself uses the WiFi to get the data via fetch() to send via messaging to the App (Clock Face).
Is there a Way to use the WiFi of the Ionic for getting data (simple text) without need of Smartphone?

11-26-2018 14:51
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-26-2018 14:51
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
There's no way to fetch without using the companion. Device wifi is only used for firmware updates and music transfer.
