RobinBobin / react-native-google-drive-api-wrapper

This wrapper facilitates the use of the Google Drive API in React Native projects.
110 stars 43 forks source link

Incorrect behavior on IOS for call driveApi.files.getBinary(fileId) #86

Closed Voznov closed 1 year ago

Voznov commented 1 year ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch @robinbobin/react-native-google-drive-api-wrapper@1.2.3 for the project I'm working on.

Problem

It's working awesome for Android. But for IOS there is reader.result which equals data:text/plain;base64,ZmVmMGI3YT... That's why it makes b64 equal to undefined and doesn't call resolve or reject

Solution

Here is the diff that solved my problem:

diff --git a/node_modules/@robinbobin/react-native-google-drive-api-wrapper/api/aux/utils.ts b/node_modules/@robinbobin/react-native-google-drive-api-wrapper/api/aux/utils.ts
index b62deb1..7bc5a5a 100644
--- a/node_modules/@robinbobin/react-native-google-drive-api-wrapper/api/aux/utils.ts
+++ b/node_modules/@robinbobin/react-native-google-drive-api-wrapper/api/aux/utils.ts
@@ -17,7 +17,10 @@ export function blobToByteArray(blob: Blob): Promise <Uint8Array | null> {
       }

       if (typeof reader.result === "string") {
-        const b64 = reader.result.split("data:application/octet-stream;base64,")[1];
+        const b64 = reader.result.split("base64,")[1];
+        if (!b64) {
+          reject({reader})
+        }

         resolve(toByteArray(b64));

This issue body was partially generated by patch-package.

XantreDev commented 1 year ago

+

RobinBobin commented 1 year ago

Thanks a lot @Voznov! I'll be very grateful if you make a pull request.

RobinBobin commented 1 year ago

@Voznov, Would you close the issue, please, if you feel it doesn't need further attention?