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
Fix AWS S3 upload on React Native #3064
Conversation
I will address the comments soon, but this does require more work, as the React Native FormData to upload expects an internal URI instead of a blob. This is what was required to make it work: diff --git a/node_modules/@uppy/aws-s3/lib/MiniXHRUpload.js b/node_modules/@uppy/aws-s3/lib/MiniXHRUpload.js
index e3c49aa..58187b2 100644
--- a/node_modules/@uppy/aws-s3/lib/MiniXHRUpload.js
+++ b/node_modules/@uppy/aws-s3/lib/MiniXHRUpload.js
@@ -108,13 +108,7 @@ module.exports = /*#__PURE__*/function () {
this._addMetadata(formPost, file.meta, opts);
- var dataWithUpdatedType = setTypeInBlob(file);
-
- if (file.name) {
- formPost.append(opts.fieldName, dataWithUpdatedType, file.meta.name);
- } else {
- formPost.append(opts.fieldName, dataWithUpdatedType);
- }
+ formPost.append(opts.fieldName, { name: file.name, type: file.type, uri: file.meta.uri })
return formPost;
};
@@ -260,7 +254,7 @@ module.exports = /*#__PURE__*/function () {
xhr.open(opts.method.toUpperCase(), opts.endpoint, true); // IE10 does not allow setting `withCredentials` and `responseType`
// before `open()` is called.
- xhr.withCredentials = opts.withCredentials;
+ // xhr.withCredentials = opts.withCredentials;
if (opts.responseType !== '') {
xhr.responseType = opts.responseType; |
Thanks @Cretezy and thanks for your contribution! We are not actively updating React Native, so any work here is really appreciated. |
Since React Native requires a URI, how would you recommend adding this functionality? In the patch above, I passed it in the meta, which works, but I don't know if there's a better way. (Specifically, I'm taking about the |
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
// before `open()` is called. | ||
xhr.withCredentials = opts.withCredentials | ||
// before `open()` is called. It’s important to set withCredentials | ||
// to a boolean, otherwise React Native crashes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
// to a boolean, otherwise React Native crashes | |
// to a boolean, otherwise React Native crashes. |
This took me hours to figure out, but React Native's XMLHttpRequest has a bug where setting
withCredentials
toundefined
crashes the app silently.This is more of a patch, because
withCredentials
can never be set (from what I can tell).