1

I use this code to upload base64

public static post(api:number, params:object = {},callback:{(success:boolean, json: any): void;})
    {
        var xhr = new XMLHttpRequest();
        xhr.open("POST", this.baseUrl+this.serverAPI, true);
        xhr.setRequestHeader('content-type', 'text/html');


        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4) 
            {
                if(xhr.getResponseHeader('content-type')==='text/html')
                {
                    let response = JSON.parse(xhr.responseText); 
                    if(response.code === -1)
                    {
                        callback(false, response);                       
                    }
                    else
                    {
                        callback(true, response);          
                    }
                } 
                else 
                {    
                    const result =  {code: -90001};
                    console.log(false, result);
                }
            }
        }
    

        params["cmd"] = api;
        const strData = JSON.stringify(params);
        cc.log("DATA:", strData);
        xhr.send(strData);
    }

and I sure it add 'Access-Control-Allow-Origin' at server

but when I prase too large base64 string , it will error

like this

enter image description here

but same picture , when i compress it
(4.3MB to 627KB)

enter image description here

it fine and could upload to server

could any one tell me how to fix it?

Mukesh Keshu
  • 467
  • 2
  • 13
Kino
  • 11
  • 2

0 Answers0