Skip to content
This repository has been archived by the owner on Mar 16, 2019. It is now read-only.

Android utf-8 coding #122

Closed
toearth opened this issue Sep 8, 2016 · 9 comments
Closed

Android utf-8 coding #122

toearth opened this issue Sep 8, 2016 · 9 comments

Comments

@toearth
Copy link

toearth commented Sep 8, 2016

The js communicates with android native use utf-8 code, when I request a binary text from server, the response type is not blob, it coded to utf-8 string. And iOS use base64 code, it works well.

@wkh237
Copy link
Owner

wkh237 commented Sep 8, 2016

Hi @windhost , could you let me know what's the Content-Type of response and how you send your request ? Thank you 👍

wkh237 added a commit that referenced this issue Sep 8, 2016
@toearth
Copy link
Author

toearth commented Sep 9, 2016

'Content-Type': 'application/octet-stream',
This is my Content-Type.

@toearth
Copy link
Author

toearth commented Sep 9, 2016

respInfo:Object
  headers:Object
    Access - Control - Allow - Headers: "Origin, X-Requested-With, Content-Type, Accept"
    Access - Control - Allow - Origin: "*"
    Access - Control - Expose - Headers: "Refresh-Token"
    Content - Length: "47"
    Content - Type: "application/octet-stream"
    Date: "Fri, 09 Sep 2016 02:48:10 GMT"
    Refresh - Token: "..4VJPjD2iKfpM-"
  __proto__ : Object
  redirects : Array[1]
  respType : ""
  rnfbEncode : "utf8"
  state : "2"
  status : 200
  taskId : "a329d05a-34d8-4291-b86e-2099d416de77"
  timeout : false

Thank you for your update, but I also can't get a blob.

This is in iOS

  respInfo: 
   { status: '200',
     state: '2',
     taskId: '62472c13-2848-4739-b211-f7f82b301944',
     headers: 
      { 'Content-Type': 'application/octet-stream',
        'Access-Control-Expose-Headers': 'Refresh-Token',
        Date: 'Fri, 09 Sep 2016 02:58:30 GMT',
        'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept',
        'Refresh-Token': '',
        'Content-Length': '47',
        'Access-Control-Allow-Origin': '*' },
     respType: 'blob',
     timeout: false,
     rnfbEncode: 'base64' },

@wkh237 wkh237 added the bug label Sep 9, 2016
@wkh237
Copy link
Owner

wkh237 commented Sep 9, 2016

@windhost , thanks for the detailed information that's really helpful, basically our network module will try to decode response data as UTF8 string, if it failed, encode the data using BASE64 encoding. Looks like this process success on Android but failed on IOS, as such it result in inconsistent behavior.

To solve this problem, I'm planning to add an extra option to fetch so that the response data will always encoded as BASE64 string, so that you can use it this way

RNFetchBlob.fetch('GET', 'http://example.com/myblob', 
{
  // extra header
  'RNFB-Response' : 'base64'                                                                                                                                                      
})
.then((res) => {
    res.base64()
})

I'll update the status in this thread once it's done 😄

@toearth
Copy link
Author

toearth commented Sep 9, 2016

You have solved this problems, that help me a lot. Thank you a thousand! I'm waiting for your update.

wkh237 added a commit that referenced this issue Sep 12, 2016
@wkh237
Copy link
Owner

wkh237 commented Sep 12, 2016

@windhost , I've published 0.9.5-beta.2 which allows you force response format.

RNFetchBlob.fetch('GET', 'http://example.com/myblob', 
{
  // extra header
  'RNFB-Response' : 'base64'                                                                                                                                                      
})
.then((res) => {
    res.text() // should be base64 encoded string
})

Please try upgrade to this version, see if it solves the problem, thank you 😄

@toearth
Copy link
Author

toearth commented Sep 12, 2016

OK, I will do this.

@toearth
Copy link
Author

toearth commented Sep 12, 2016

It works on android. Thank you for you reply!
respType:"" rnfbEncode:"base64" state:"2" status:200

@wkh237
Copy link
Owner

wkh237 commented Sep 12, 2016

Great ! 👍 Nice to know it works 😄

@wkh237 wkh237 closed this as completed Sep 21, 2016
zombierabbit pushed a commit to zombierabbit/react-native-fetch-blob that referenced this issue Feb 12, 2019
Wanted to include a note for folks upgrading from the old branch to the new branch about renaming all product references as this was a problem I came across in wkh237#122 (joltup#122)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants