Skip to content
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

Incorrect response.data/response.base64 for Android when using fetch #442

Closed
oleksandr-dziuban opened this issue Sep 26, 2019 · 18 comments
Closed

Comments

@oleksandr-dziuban
Copy link

oleksandr-dziuban commented Sep 26, 2019

Hello @Traviskn @mheins57
After the latest 0.11.1 version release I have tried to add this new version to my project and fount possibly regression issue on Android:

When we are using

const response = await RNFetchBlob.fetch('GET', uri);
const imageData = response.data;
const imageBase64 = response.base64();

response.data looks broken, previuosly it was simple base64 string.
response.base64() throws an error


Uncaught InvalidCharacterError {message: "The string to be encoded contains characters outside of the Latin1 range."}

In version 0.10.16 everything looks fine. On iOS both versions are working fine.
I'm using react-native@0.61.1

As example i'm fetching this file: https://api-dev01.elateral-dev.io/file/dev01/S1GbfMFDN
And get broken response.data instead of normal base64 string:

"�����JFIF������C������������������������������������������������������������������C����������������������������������������������������������������������t������������������������	
�����F��������	����������������!	�13�"#AQRSs���a���$2Bbq��C���
5c���������������������	��C�������	������������!��1"A��2Qaq����#BRs������3S�Cb�$r����%���������?�Hc�h_4/t/�l�
��
z����7������Nd�9'����>�W����������'���`���L�x0k��I�G�X;b��~S>����������ؾ�_�χ�������僶/���3������'���`���L�x0k��I�G�X;b��~S>����������ؾ�_�χ�������僶/���3������'���`���L�x0k��I�G�X;b��~S>����������ؾ�_�χ�������僶/���3������'���a2p��g͍>i=�j�|�Rq������G��ՇԎ������՘���)�������ǃ����/����~v�|&<���������X�EUc�����v�_�˶�_4�]��>���jS�"砸���appa./k����papp`�������/n�80a2w�g�'�'�S����}I�?��ȘP������7�g�����˓�$���Ly�����s��Q��d���f|�r����Lv��9���n߉Ͽ����������ՙ�>Q�i̟9��8���W�sl�e��i�bDm3�)W��M����Q[�I�2+l�,[�l�%��4���%���*��l&���VatE!Y�ؐB�V��E����ٖF���nj�e��n9s$v�����&Q��e�F��+�X�P�g�l�d��N�X�����Q��J?>k����\��$��#p�%2S���%%<�;/���;vJ�H��k���:����KΘ٤���X��}���̦=Lj�yM�h��"-�����epLɧ<����ε�$:�l��D�eY۽Je��5/��κBI�P�9��BM:��
.ASڱh�s���'0�ڎ�!r��iX�dfQ�2J�u����N�����Y�IaC��}k[����M�R)�Th�r_�/��$c��K�@<|�����`[%�����+>I�S��EOR[1|�e"*��W���,�'�H&�5h�H�4��<���������	�\gĹ�GM�We�r��v�C�Y!yr���)>_��jZYdJ�)�WTf�ӵ����Wo�Rub\�j�x�Y�����������0#H�9f� �X�ܩ�q����(��Y��Xɏ���xB�zJ��ia��5��S�+v�Ic��`�.ie~�1�"%")��`�Zh����I�W]�eT\-KW�d�!��.�(�?�����5�Z���*Jh�7�Ҝ=D��i桒���2����=�|�+��i#�Fʶ����bC��O�X�0%d��c(����3�R+���(��*3����K,�h�
�#�T���z�t�4��eI#�*��$��#t:�r�Ӵ�����WǾ�����l�$���VoB�rjţ��+�#J�CUĔ�f5S���heC
F_�qQ��O_-U1x���G��� ���!AdzZ�V���k����d��������^(q���Y=�Q:
�d��s���r������ezh�Z���51IQD��5�B�3���yW��=0m�'���f<�ǼI��\IA��SRI�g6I��[�V�2��(syjg�si��������E��.��Z�0�*��Ww�qk�A����X�5Lm���ȟc!R�-�l�,!XT����H�Q����k��T�UP�>��y�̧�%��&����54cƥ�JI�'�秬AN�J��T�Ť���7�g~��2�*
����Zl�+�3Z��j+����2�8�3���i����&z�"	%D<QL�(@2ƽ �e���B����ō8%|J������Vr���~ӫ�%��k[",VG-Y;��H��琤4��G3h���e��f���8^L�6+M�]���>4c�Vt�B���4���W��qͨ�ϐ�M-5l2�&SMsVE�C��B��'���L�8�Z�ML�K��$���̨��&iċ~j��������FKk�F��1�N��1$I�e�����0�Ҙb+�6�3��ҾQ��hyt�
��b�� i�<��&�Rf��4���3�������	��v�d΅Vi�HjzjPb�5���㆒���S�-3� ��ѕ�d�Wx�Fw�g�'�'S�����Ry����&����B�
���}g��7���I?;b���pp`�c���Q���c��-�I��8����:�����R�������	�U1�D�����rѬt������
��[)���FA2�j�uew'�,�,��MS&��ۡ�/�a��7^YHC�2���xtF@"�=:��)%�"��\��Q�r��6X�WJ��W-������;R�W�4r�:�ֽ7�wX���5x�IP�>�j���^�L���������bx����z���@Ab������C����ǚAr�����é�/����k�ᚩ�W���&@�p��`�;������3�U�]��$BL����V���J|��$�zj�W(�;
ӤD�]�����O�ܒ1�����s�b�*x�i*�r�k4��Ҫ��%�l0e�n�7'�>��:�
���k�|�QXE����S����܌�xsV0+}k�gD��L�d �m;���H2J�+�ͦ4�SG-u4�L��Z#���[�̓�%��RK����5J��E� �g���%W�R.iM�TRdم%E+��e�Q��H�A4T����Z|���zj�k7Ɏ�KP��Td��6d��ǥÇ&�����Gd"V�\�6�֞��P���M��N�v�}�XS��"ˈ�䕙_��F���犓1�T��εM�9�M%mB=8d��іSS���h���P�K���(�o����"���(�s^��d��s�e�c���ܻ5�2��1Te�#M�y�ueBT>sKGV��RR�Q��
�k�;�~
^)����rC���e:�)��d�c�AB	�
$�B�>���c���6�t�8,��g����UA΢�s������znf��r��8^

Could you please check this issue on Android please?
Thank you

@KrzysztofSakowski
Copy link

@oleksandr-dziuban I am also experiencing broken fetch on 0.11.1 version on Android. Could you wrap the fetch from your sample code with try/catch and tell me if you are having following error:

RNFetchBlob failed. Download interrupted

@oleksandr-dziuban
Copy link
Author

@KrzysztofSakowski In my case i'm just fetching file and use it as base64 string.
I have try/catch here and it says:
Uncaught InvalidCharacterError {message: "The string to be encoded contains characters outside of the Latin1 range."}

@oleksandr-dziuban
Copy link
Author

@KrzysztofSakowski just in response we have incorrect data on Android.
Maybe something went wrong in one of this PRs:
https://github.com/joltup/rn-fetch-blob/releases/tag/v0.11.0

@Traviskn
Copy link

There was a PR that changed string encoding, ill see if I can figure out which PR caused the regression

@oleksandr-dziuban
Copy link
Author

@Traviskn Thanks a lot

@Traviskn
Copy link

#353 changed character encoding, so I suspect it may be the cause. We need to test a branch with this commit reverted to see if the problem goes away. I’ll probably have time later today to test it, but if someone else can test sooner please comment here with your findings

@oleksandr-dziuban
Copy link
Author

Just if/else statement deleted here: default data format in response should be base64. If utf-8 requested we need to have utf-8 response

if(responseFormat == ResponseFormat.UTF8) {
                                callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_UTF8, "");
                            }
                            else {
                                callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_BASE64, android.util.Base64.encodeToString(b, Base64.NO_WRAP));
                            }

@Traviskn
Copy link

Great find! Would you be able to open a PR to add back that if/else statement?

@oleksandr-dziuban
Copy link
Author

oleksandr-dziuban commented Sep 26, 2019

Great find! Would you be able to open a PR to add back that if/else statement?

Not sure if I can compile Java code to check everything. I'm working with JavaScript side only :)

@Traviskn
Copy link

Ok, I’ll see about adding back the case for base 64 and opening a PR as soon as I can

@oleksandr-dziuban
Copy link
Author

Thank you 👍

@Traviskn
Copy link

unfortunately this is not going to be quite as simple as just adding back the if/else statement as more of the surrounding workflow was changed by #353, I will likely need to end up reverting it

@Traviskn
Copy link

I've reverted #353 and published a new version, 0.11.2

@oleksandr-dziuban
Copy link
Author

@Traviskn thanks! I will add this latest version and test

@oleksandr-dziuban
Copy link
Author

@Traviskn Everything looks good on Android, Thanks a lot! Closing this issue...

@saadmutahar
Copy link

saadmutahar commented Jan 27, 2020

Hi @Traviskn @oleksandr-dziuban
I am trying with the lates version and the issue is still coming in android.

I am using
`RNFetchBlob.fetch('POST', REQUEST_URL,
{

            'Accept': 'application/json',
            'Content-Type': 'multipart/form-data',
        },
        data
        )
        .then((response) => response.json())
        .then((responseData) => {
            console.log(responseData); })`

response data looks broken
I'm using react-native@0.61.3

I am getting a broken response data instead of normal string.
Example:
Message: "ت� ا�تح��� ب�جاح "

@anyway2019
Copy link

same issue in version 0.12.0
the response :

 "data": "� ��",

the request:

 RNFetchBlob.fetch('GET',url,{
       'Content-Type': 'application/octet-stream',
       'User-Agent': getUserAgend(),
       "Access-Control-Allow-Origin": "*",
     })
     .then((res) => {
       let status = res.info().status;
       console.log(92,res);
       if(status == 200) {
         // the conversion is done in native code
         let base64Str = res.base64()
         success(base64Str)
       } else {
         error(JSON.stringify('upload failed!'))
       }
     })
     // Something went wrong:
     .catch((errorMessage, statusCode) => {
       if (errorMessage) error(JSON.stringify(errorMessage))
     })

@hiftikha
Copy link

Any update on this? We're also facing the issue on Android

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants