Slow reading of a very large string

Asked

Viewed 49 times

0

I’m missing a lot of performace doing a decodeBase64, when I have a very large file type 30MB, it takes a long time to read the data received from the front.

Is there any way to improve the reading of this file that is in fileBase64?

On the front the file is like this:

reader.onload = function (readerEvt) {
        var anexosTemp = [];
        $scope.$apply(function () {
           var binaryString = readerEvt.target.result;
           var fileBase64 = btoa(binaryString);

           anexoVO = {
              dados: fileBase64,
              nome: vm.anexo.arquivo.name,
              descricao: vm.anexo.descricao,
              tamanho: vm.anexo.arquivo.size,
              tipo: vm.anexo.arquivo.type,
           };

           anexosTemp.push(anexoVO);
           vm.anexo = null;

        });

        var url = null;

        if ($location.host() === "localhost") {
           url = "xxxxxxxxxxxxxxxx";
        } else {
           url ="xxxxxxxxxxxxxxx";
        }

        var configHttp = {
           transformRequest: angular.identity,
           headers: {
              'Content-Type': undefined
           }
        };

        var formulario = new FormData();
        vm.solicitacao.anexos = anexosTemp;
        formulario.append("file", JSON.stringify(vm.solicitacao));

        $http.post(url, formulario, configHttp)

In Java I do this:

@Consumes(MediaType.MULTIPART_FORM_DATA)
public CSResponse adicionarArquivo(String strSolicitacao){
String[] str = strSolicitacao.split("file\"");
    String[] str2 = str[1].trim().split("------");
    String solJson = str2[0].trim();
    Gson g = new GsonBuilder().registerTypeAdapter(Date.class, new 
    GsonUTCDateAdapter()).create();
    Sol sol = g.fromJson(solJson, Sol.class);
}

Only this process in reading my attribute dados It takes a long time when it is reading. How do I improve the reading performance of this string gigante that comes through my js and this make with this JSON be faster converted?

  • because you use btoa to convert it to Base64 in js se in java you return it to byte array?

  • Cara had asked the wrong question, I rephrased my question, the problem is when I convert to JSON.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.