Browse Source

Merge pull request #479 from sadafk831/master

(Android) Fix multi-byte UTF-8 issue : Translating the non english language data properly
Travis Nuttall 5 years ago
parent
commit
577556d752
No account linked to committer's email address
1 changed files with 5 additions and 3 deletions
  1. 5
    3
      android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

+ 5
- 3
android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java View File

514
                             String utf8 = new String(b);
514
                             String utf8 = new String(b);
515
                             callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_UTF8, utf8);
515
                             callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_UTF8, utf8);
516
                         }
516
                         }
517
-                        // This usually mean the data is contains invalid unicode characters, it's
518
-                        // binary data
517
+                        // This usually mean the data is contains invalid unicode characters but still valid data,
518
+                        // it's binary data, so send it as a normal string
519
                         catch(CharacterCodingException ignored) {
519
                         catch(CharacterCodingException ignored) {
520
+                            
520
                             if(responseFormat == ResponseFormat.UTF8) {
521
                             if(responseFormat == ResponseFormat.UTF8) {
521
-                                callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_UTF8, "");
522
+                                String utf8 = new String(b);
523
+                                callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_UTF8, utf8);
522
                             }
524
                             }
523
                             else {
525
                             else {
524
                                 callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_BASE64, android.util.Base64.encodeToString(b, Base64.NO_WRAP));
526
                                 callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_BASE64, android.util.Base64.encodeToString(b, Base64.NO_WRAP));