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

Implement Blob support for XMLHttpRequest #11573

Closed
wants to merge 76 commits into from
Closed

Implement Blob support for XMLHttpRequest #11573

wants to merge 76 commits into from

Conversation

satya164
Copy link
Contributor

@satya164 satya164 commented Dec 20, 2016

This PR is a followup to #11417 and should be merged after that one is merged.

What does the PR do?

  1. Add support for creating blobs from strings, not just other blobs
  2. Add the File constructor which is a superset of Blob
  3. Add the FileReader API which can be used to read blobs as strings or data url (base64)
  4. Add support for uploading and downloading blobs via XMLHttpRequest and fetch
  5. Add ability to download local files on Android so you can do fetch(uri).then(res => res.blob()) to get a blob for a local file (iOS already supported this)

Test plan

  1. Clone the repo https://github.com/expo/react-native-blob-test
  2. Change the package.json and update react-native dependency to point to this branch, then run npm install
  3. Run the server.js file with node server.js
  4. Open the index.common.js file and replace localhost with your computer's IP address
  5. Start the packager with yarn start and run the app on your device

If everything went well, all tests should pass, and you should see a screen like this:

screen shot 2017-06-08 at 7 53 08 pm!

Pull to rerun all tests or tap on specific test to re-run it

Release Notes

[GENERAL] [FEATURE] [Blob] - Implement blob support for XMLHttpRequest

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @mkonicek and @javache to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Dec 20, 2016
@mkonicek
Copy link
Contributor

mkonicek commented Feb 1, 2017

Would it be possible to revert the changes in the 2048 example to make this PR easier to review (less changed files)? Also does the 2048 example need changes? Probably doesn't do HTTP requests?

@satya164
Copy link
Contributor Author

satya164 commented Feb 1, 2017

cc @grabbou could you revert those changes please?

@brentvatne
Copy link
Collaborator

ping @grabbou

@shergin shergin added Android Platform: iOS iOS applications. labels May 30, 2017
@satya164 satya164 changed the title [WIP] Implement Blob support for XMLHttpRequest Implement Blob support for XMLHttpRequest Jun 8, 2017
@@ -198,6 +198,7 @@
"serve-static": "^1.13.1",
"shell-quote": "1.6.1",
"stacktrace-parser": "^0.1.3",
"uuid": "^3.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? uuid has been in use without this dependency (see https://github.com/facebook/react-native/pull/11573/files#diff-d7db9e5e49c3ea163f89547a0be6a438L19 in this PR).

This is one of the blockers, as adding the uuid package may conflict with another uuid dependency that we use internally at Facebook.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks kind of bad, it probably only works because of some transitive dependency that also includes uuid.

Not sure what the best solutions would be, we could vendor the uuid module used internally or maybe add it to fbjs.

Another solution that could work is to use the uuid v4 import directly so require('uuid/v4') (https://github.com/kelektiv/node-uuid#quickstart---commonjs-recommended)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per #16543 looks like the missing uuid package is causing issues for some folks.

@hramos
Copy link
Contributor

hramos commented Jan 24, 2018

This is now in a good state internally and ready to land. Just need to get it looked at one more time by another Facebook employee. Once it's approved internally, I'll land it.

Adding commits to the PR resets the diff to Needs Review internally so let's avoid doing that for now. We're so close!

@serhiipalash
Copy link

serhiipalash commented Jan 26, 2018

Thanks to everyone who did this!

@Kureev
Copy link
Contributor

Kureev commented Jan 26, 2018

Woah! This is huuuge! 🔥🔥🔥

@terribleben
Copy link
Contributor

image

@mkonicek
Copy link
Contributor

mkonicek commented Jan 26, 2018

OMG it's merged! Amazing work @satya164 and reviewers!

@janicduplessis
Copy link
Contributor

Thanks to everyone involved!! The PR actually has commits from 6 different persons + 6 additional reviewers!

@sibelius
Copy link

sibelius commented Feb 8, 2018

landed on RN53 or RN54?

@hramos
Copy link
Contributor

hramos commented Feb 8, 2018

@sibelius you can check which releases a commit belongs to by looking at the tags on the commit itself. If you go to be56a3e, you can see it does not belong to any release yet (it's only tagged master as of this writing). This commit should get picked up the next time a release candidate is packaged.

rozele pushed a commit to microsoft/react-native-windows that referenced this pull request Mar 1, 2018
Summary:
This PR is a followup to facebook/react-native#11417 and should be merged after that one is merged.

  1. Add support for creating blobs from strings, not just other blobs
  1. Add the `File` constructor which is a superset of `Blob`
  1. Add the `FileReader` API which can be used to read blobs as strings or data url (base64)
  1. Add support for uploading and downloading blobs via `XMLHttpRequest` and `fetch`
  1. Add ability to download local files on Android so you can do `fetch(uri).then(res => res.blob())` to get a blob for a local file (iOS already supported this)

  1. Clone the repo https://github.com/expo/react-native-blob-test
  1. Change the `package.json` and update `react-native` dependency to point to this branch, then run `npm install`
  1. Run the `server.js` file with `node server.js`
  1. Open the `index.common.js` file and replace `localhost` with your computer's IP address
  1. Start the packager with `yarn start` and run the app on your device

If everything went well, all tests should pass, and you should see a screen like this:

![screen shot 2017-06-08 at 7 53 08 pm](https://user-images.githubusercontent.com/1174278/26936407-435bbce2-4c8c-11e7-9ae3-eb104e46961e.png)!

Pull to rerun all tests or tap on specific test to re-run it

  [GENERAL] [FEATURE] [Blob] - Implement blob support for XMLHttpRequest
Closes facebook/react-native#11573

Reviewed By: shergin

Differential Revision: D6082054

Pulled By: hramos

fbshipit-source-id: cc9c174fdefdfaf6e5d9fd7b300120a01a50e8c1
@laurent22
Copy link

Is there any documentation for using blobs?

@satya164
Copy link
Contributor Author

MDN is your friend

@laurent22
Copy link

Ok I missed that it was an implementation of the standard, I thought it was more like rn-fetch-blob. Some doc about it would probably help anyway. I'll submit a pull request if I can get it to work.

@SudoPlz
Copy link
Contributor

SudoPlz commented Nov 22, 2019

@laurent22 did you figure it out?

I'm still struggling with understanding how to create a Blob out of a local file file:///blablabla/blabla from the device photo library, so that I can then upload it somewhere.

Thanks

@laurent22
Copy link

I've never figured it out, so I've ended up using rn-fetch-blob

@SudoPlz
Copy link
Contributor

SudoPlz commented Nov 22, 2019

@laurent22 just figured this out.

It's a lot simpler that what I imagined.

Check this out: https://stackoverflow.com/a/59002760/1658268

I hope this saves time from others looking to do the same thing.

facebook-github-bot pushed a commit that referenced this pull request Jun 17, 2022
Summary:
The eslint community config does not have the File and Blob polyfills in `globals` which have been part of the Javascript implementation for ~3 years. They were added to the Javascript API in #11573 by satya164.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Fixed] - Added File and Blob globals to eslint community config

Pull Request resolved: #31293

Test Plan:
Evidence these globals exist:
1. #11573
2. Executed the following:
<img width="421" alt="Screen Shot 2021-04-02 at 12 08 50 PM" src="https://user-images.githubusercontent.com/3495974/113432946-466ae280-93ac-11eb-899c-3ca124e0af84.png">
<img width="317" alt="Screen Shot 2021-04-02 at 12 11 56 PM" src="https://user-images.githubusercontent.com/3495974/113433156-a82b4c80-93ac-11eb-99dc-0840d5ad9078.png">

3. Receive in console:
<img width="603" alt="Screen Shot 2021-04-02 at 12 09 59 PM" src="https://user-images.githubusercontent.com/3495974/113432996-5da9d000-93ac-11eb-81c6-88e6b059c733.png">
<img width="599" alt="Screen Shot 2021-04-02 at 12 12 27 PM" src="https://user-images.githubusercontent.com/3495974/113433174-b711ff00-93ac-11eb-8820-67039696f6ce.png">

Evidence the PR works: the globals in the PR identical to the others in the eslint community config that they are in

Reviewed By: cipolleschi

Differential Revision: D37214364

Pulled By: cortinico

fbshipit-source-id: 71b9dec8d222a057c54f6cde6c6d8e85dd25f6f9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Platform: iOS iOS applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet