Skip to content

Trashcoder/blob slice content type #38078

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

Closed
wants to merge 6 commits into from
Closed

Trashcoder/blob slice content type #38078

wants to merge 6 commits into from

Conversation

trashcoder
Copy link
Contributor

@trashcoder trashcoder commented Jun 26, 2023

Summary:

I added the contentType parameter to Blob.slice like it's in the MDN Web docs.
This PR fixes #38058

When i slice a Blob for chunked uploads with react native i lost the content type, e.g. "image/jpeg", so the server doesn't know what kind of file he gets. In the docs of MDN the slice method was described with a third contentType parameter which was missing in Metas implementation.

Changelog:

[GENERAL] [ADDED] added a third parameter "contentType" to method slice of class Blob.

Test Plan:

I tested it with the unit-tests:
yarn run test Blob-test.js
yarn run v1.22.19
$ jest Blob-test.js
PASS packages/react-native/Libraries/Blob/tests/Blob-test.js
Blob
✓ should create empty blob (5 ms)
✓ should create blob from other blobs and strings
✓ should slice a blob (1 ms)
✓ should slice a blob and sets a contentType
✓ should close a blob (4 ms)

My added unit test results "✓ should slice a blob and sets a contentType".

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 26, 2023
@analysis-bot
Copy link

analysis-bot commented Jun 26, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 9,041,930 -270
android hermes armeabi-v7a 8,292,594 +614
android hermes x86 9,559,053 +260
android hermes x86_64 9,400,740 -58
android jsc arm64-v8a 9,601,108 -280
android jsc armeabi-v7a 8,729,088 +579
android jsc x86 9,689,108 +236
android jsc x86_64 9,934,815 -130

Base commit: 71f715a
Branch: main

@trashcoder
Copy link
Contributor Author

Is there something i can do to make the PR pass? It seems these 3 fails were there because of a server error.

@Pranav-yadav
Copy link
Contributor

Congrats on your 1st PR to RN 🎉

Is there something i can do to make the PR pass? It seems these 3 fails were there because of a server error.

Those seem transient issues, unrelated to changes in this PR so no need to worry about them.
Apart from that could you please link the respective issue to this PR? By mentioning below in the PR description:
Fixes #38058

@trashcoder
Copy link
Contributor Author

Apart from that could you please link the respective issue to this PR?

done.


blob.data.size = 34546;

const slice = blob.slice(0, 2354, 'text/plain');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const slice = blob.slice(0, 2354, 'text/plain');
const slice = blob.slice(0 /* start */, 2354 /* end */, 'text/plain' /* contentType */);

Not necessary to do this, still it's better to make tests more readable like this or some other way

Copy link
Contributor

@Pranav-yadav Pranav-yadav left a comment

Choose a reason for hiding this comment

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

Left format suggestions and tips.

Also, something important this PR doesn't add is "negative tests".
We should always add the tests for negative cases e.g. malformed & empty contentType

P.S.: This practice has helped me avoid potential regressions 😅

Overall, this is awesome ❤️

@@ -77,6 +77,18 @@ describe('Blob', function () {
expect(sliceC.data.offset).toBe(34543);
expect(sliceC.size).toBe(Math.min(blob.data.size, 34569) - 34543);
});

Copy link
Contributor

Choose a reason for hiding this comment

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

@trashcoder You should always run yarn lint && yarn prettier before commiting 🚀 :)

@Pranav-yadav
Copy link
Contributor

Pranav-yadav commented Jun 27, 2023

@trashcoder You should always run yarn lint && yarn prettier before commiting 🚀 :)

Can i still make these changes with yarn lint and yarn prettier? or would that be another PR?

In this PR only. It's part of the development Workflow you can check the the guide here: https://reactnative.dev/contributing/how-to-contribute-code#development-workflow

For the scope of this PR below commands should suffice:

  • running yarn lint will run eslint for JS, TS, etc. which performs linting/static analysis and makes sure our code bug free. 😃
  • running yarn prettier will run prettier which is used to format/prettify our code 💅
  • running yarn test will run the tests using jest; the existing tests and new ones added by you.

Let me know if you need any further help.

@blakef
Copy link
Contributor

blakef commented Jun 27, 2023

LGTM, fix the formatting and we should get this in.

@blakef blakef self-assigned this Jun 27, 2023
@trashcoder
Copy link
Contributor Author

@blakef formatting is already fixed.

@facebook-github-bot
Copy link
Contributor

@blakef has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@blakef
Copy link
Contributor

blakef commented Jun 27, 2023

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jun 27, 2023
@facebook-github-bot
Copy link
Contributor

@blakef merged this pull request in e35ca71.

@trashcoder trashcoder deleted the trashcoder/Blob_slice_contentType branch July 6, 2023 06:47
facebook-github-bot pushed a commit that referenced this pull request Jul 6, 2023
Summary:
For the contentType Parameter of the method slice in Class Blob which was fixed for
#38078
 the typescript declaration is missing.

## Changelog:
[GENERAL] [ADDED] - Added contentType parameter to Blob declaration

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: #38163

Test Plan: I ran yarn run test-typescript and check with Webstorm and VSCode.

Reviewed By: rshest

Differential Revision: D47228992

Pulled By: javache

fbshipit-source-id: fd767bb47c5e64657bfafba4c84d1d8671857109
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. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blob.slice Parameter contentType does not exists in iOS and Android.
6 participants