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,11 +514,13 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
514 514
                             String utf8 = new String(b);
515 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 519
                         catch(CharacterCodingException ignored) {
520
+                            
520 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 525
                             else {
524 526
                                 callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_BASE64, android.util.Base64.encodeToString(b, Base64.NO_WRAP));