question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option to pass body to fetchBlob

See original GitHub issue

Is your feature request related to a problem? Please describe.

I am trying to download a big file using our API

const options: BlobFetchInput = {
  method: 'POST',
  filename: 'offline.db',
  headers: {
    Authorization: `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  android: {
    target: 'data'
  },
  mimeType: 'application/octet-stream',
  url: `${apiUrl}api/v1/client-db/clone`
};

const response = await BlobCourier.fetchBlob(options);

JSON body with request parameters must be part of the request but unfortunatelly I didn’t find such option for fetchBlob.

Describe the solution you’d like

I want my request to look like this:

const options: BlobFetchInput = {
  method: 'POST',
  filename: 'offline.db',
  headers: {
    Authorization: `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ facilityIds })
  android: {
    target: 'data'
  },
  mimeType: 'application/octet-stream',
  url: `${apiUrl}api/v1/client-db/clone`
};

Describe alternatives you’ve considered

At the moment I use FileSystem.fetch from react-native-file-access but unfortunately it doesn’t provide a way to cancel a long request:

const options = {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  path: getDatabasePath(dbName),
  body: JSON.stringify({ facilityIds })
};
const url = `${apiUrl}api/v1/client-db/clone`;
const response = await FileSystem.fetch(url, options, onProgress);

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
edeckerscommented, Dec 17, 2021

I totally get where you’re coming from, hopefully react-native-file-access solves the issue for you. Either way I’m still considering adding this feature in January / early 2022, so make sure to check back every now and then!

1reaction
edeckerscommented, Dec 10, 2021

It’s not too complicated in terms of code complexity, but I think it will amount to quite some lines and changes; more than you’d expect anyway. Something along the lines of https://github.com/edeckers/react-native-blob-courier/pull/141/files, and that PR doesn’t even include tests yet; typically each PR adds multiple tests for TypeScript, Android and iOS.

So I’d like to add the feature and help you out, but as you can imagine December isn’t the best month to find time for that, what with the Holidays and all that stuff going on. January seems feasible for me.

In addition I’d like to mention that I welcome PR’s, if you feel like making a start yourself! Should you consider doing so, let’s figure out a contract for the interface together before you start working on it, so your hard work won’t be for naught.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the Fetch API - MDN Web Docs
The Fetch API provides a JavaScript interface for accessing and manipulating parts of the protocol, such as requests and responses.
Read more >
Fetch: Basics - Modern JavaScript Eğitimi
So we can check HTTP status, to see whether it is successful or not, check headers, but don't have the body yet. The...
Read more >
Trying to use fetch and pass in mode: no-cors - Stack Overflow
So I am trying to pass in an object, to my Fetch which will disable CORS, like so: fetch('http://catfacts-api.appspot.com/api/facts?number=99', ...
Read more >
Fetch API (JavaScript)- How to Make GET and POST Requests
Syntax: · Method: The request method is either GET or POST. · Headers · Body: The body can be any of the following:...
Read more >
fetch documentation
Body methods · text() - yields the response text as String · json() - yields the result of JSON.parse(responseText) · blob() - yields...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found