Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

fetch not working

ANSWERED

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

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

You're confusing code which must be run in the companion, not on the device. fetch() is companion only.

View best answer in original post

Best Answer
5 REPLIES 5

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.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

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 😕

Best Answer
0 Votes

You're confusing code which must be run in the companion, not on the device. fetch() is companion only.

Best Answer

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?

Best Answer
0 Votes

There's no way to fetch without using the companion. Device wifi is only used for firmware updates and music transfer.

Best Answer