Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to pass body to fetchBlob #170

Open
ezze opened this issue Nov 19, 2021 · 10 comments · May be fixed by #191
Open

Option to pass body to fetchBlob #170

ezze opened this issue Nov 19, 2021 · 10 comments · May be fixed by #191
Assignees
Labels
Projects
Milestone

Comments

@ezze
Copy link

ezze commented Nov 19, 2021

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);
@edeckers
Copy link
Owner

Hi @ezze , thank you for your suggestion! It seems like a fair request: I'll put it on the backlog and link this issue to the PR as soon as I find the time to work on it.

@edeckers edeckers self-assigned this Nov 20, 2021
@edeckers edeckers modified the milestones: 2.0.6, 2.0.7, 2.0.8 Nov 20, 2021
@ezze
Copy link
Author

ezze commented Nov 22, 2021

@edeckers Great! Thank you for a quick reply! I really appreciate your efforts on supporting this feature! It would be awesome to have this one.

@ezze
Copy link
Author

ezze commented Dec 7, 2021

@edeckers Just wanted to ask you whether it's difficult to implement this feature in the lib. I know, you support it in your free time so it's not a request from me.

I am considering options to interrupt uploads/downloads. While option to interrupt uploads only is available in react-native-blob-courier I was thinking to switch to downloadFile from react-native-fs but unfortunately (suprisingly) it can't work with methods other than GET: itinance/react-native-fs#407 🙄

@edeckers
Copy link
Owner

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.

@ezze
Copy link
Author

ezze commented Dec 15, 2021

@edeckers Thanks for your reply, mate. The project I am working on at the moment is my first React Native application so I'm not sure that it will be easy for me to dig into the issue and implement the feature I need in a short time range. Although, it's interesting for me. I have to spend some time to understand how all these native things are built and work first.

So I'll look for a cheaper way to implement the required feature by trying another libs. But if I have no luck and our business partners are ready to pay for this then I'll back to you and dig into implementing this feature.

Thanks for your responsiveness and helpfulness. Really appreciate it!!!

@edeckers
Copy link
Owner

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!

@ezze
Copy link
Author

ezze commented Dec 17, 2021

@edeckers I like your library too much so decided to migrate to GET request with query parameters instead of POST with body as a temporary workaround. It was before author of react-native-file-access had impemented the missing feature, so I'm happy with current solution now. 🎉

@edeckers
Copy link
Owner

Haha, thanks for the compliment and nice workaround!

@edeckers edeckers added this to Backlog in Planned Dec 22, 2021
@edeckers edeckers modified the milestones: 3.0.1, 3.0.2 Dec 29, 2021
@edeckers edeckers modified the milestones: 3.0.2, 3.0.5 Jan 17, 2022
@edeckers edeckers linked a pull request Jan 17, 2022 that will close this issue
9 tasks
@edeckers edeckers linked a pull request Jan 18, 2022 that will close this issue
9 tasks
@EduFrazao
Copy link

It is a very nice feature.
I'm also using react-native-file-access to download files beucase the lack of send body data on post requests.

@edeckers
Copy link
Owner

Hi @EduFrazao , thank you for reaching out! I agree that this is a nice and even missing feature that I'd love to add. There have been some unforseen life events (nothing too serious) for me though, which resulted in me not being able to find the right time and mindset to pick this up.

Still planning on adding it, but right now I can't make any actual promises about when I'll get to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Planned
  
Backlog
Development

Successfully merging a pull request may close this issue.

3 participants