NIFCLOUD-mbaas / ncmb_android

ニフクラ mobile backend Android SDK
Other
25 stars 23 forks source link

4系のAndroid端末でレスポンスの検証設定を有効にし、ファイル登録などを行うとエラーが発生する #73

Closed n0guch1 closed 6 years ago

n0guch1 commented 8 years ago

不具合の概要(Description of bug)

hocnguyen commented 7 years ago

I tested on Android version 4.2.2 (API 17) . But I upload file and get content file success, no error . My code :

NCMBAcl acl = new NCMBAcl();
        acl.setPublicWriteAccess(true);
        acl.setPublicReadAccess(true);
        byte[] data = "Hello,NCMB".getBytes();
        NCMBFile file = new NCMBFile("Hello.txt", data,acl);
        file.saveInBackground(new DoneCallback() {
            @Override
            public void done(NCMBException e) {
                if (e != null) {
                    //失敗
                } else {
                    //成功
                }
            }
        });

NCMBFile file = new NCMBFile("Hello.txt");
        file.fetchInBackground(new FetchFileCallback() {
            @Override
            public void done(byte[] data, NCMBException e) {
                if (e != null) {
                    //失敗
                } else {
                    //成功
                }
            }
        });

Please help me confirm about that.

ndyuya commented 7 years ago

Did you enable the response validation?

NCMB.enableResponseValidation(true);
hocnguyen commented 7 years ago

@ndyuya さん It has error when we enable the response validation. But only POST method, Get method is no error.

hocnguyen commented 7 years ago

@ndyuya さん、 I see we have 2 results response data with Android 4.2.2 and 5.1.1 at responseSignatureCheck() of NCMBConnection file. Response data Android 4.2.2 :

{"createDate":"2016-12-13T07:03:21.574Z","fileName":"Hello.txt"}

Response data Android 5.1.1

{"fileName":"Hello.txt","createDate":"2016-12-13T07:06:11.422Z"}

If we change format of return data response of Android 4.2.2 similar with Android 5.1.1. It is ok. No error. So in this is error, we need to fix return data from mbaas server for Android version 4.2.2. Is it right?

ndyuya commented 7 years ago

res.responseData in NCMBConnection.java:L183 is JSONObject type that deserialized HTTP response body. ( NCMBResponse.java:L24 ) It is serialized again. res.responseData.toString () at same line. I think ,it(re-serialization) may be the cause ,not server response.

hocnguyen commented 7 years ago

yes. Now I see it return 2 results different when parse JSON at NCMBResponse.java

responseData = new JSONObject(new String(sb));

I think the cause from here.