I'm trying to import a larger JSON with 5MB up to 8MB into my REALM database in a react native app with AXIOS.
All other calls from same API with less data works fine, but when I try this specific call "linksearch3" that returns this amount data (5MB) I receive the error:
> { [Error: Network Error] config: { url:
> 'myapi/path/linksearch3?cdColaborador=7442',
> method: 'get',
> headers:
> { Accept: '*/*',
> 'X-Session-ID': 'my-session-id-1234',
> 'Accept-Encoding': 'gzip, deflate, br',
> Connection: 'keep-alive' },
> baseURL: 'http://myip.com:8080/',
> transformRequest: [ [Function: transformRequest] ],
> transformResponse: [ [Function: transformResponse] ],
> timeout: 0,
> adapter: [Function: xhrAdapter],
> xsrfCookieName: 'XSRF-TOKEN',
> xsrfHeaderName: 'X-XSRF-TOKEN',
> maxContentLength: Infinity,
> maxBodyLength: Infinity,
> validateStatus: [Function: validateStatus],
> transitional:
> { silentJSONParsing: true,
> forcedJSONParsing: true,
> clarifyTimeoutError: false },
> data: undefined }, request: { UNSENT: 0,
> OPENED: 1,
> HEADERS_RECEIVED: 2,
> LOADING: 3,
> DONE: 4,
> readyState: 4,
> status: 0,
> timeout: 0,
> withCredentials: true,
> upload: {},
> _aborted: false,
> _hasError: true,
> _method: 'GET',
> _perfKey: 'network_XMLHttpRequest_http://myip.com:8080/myapi/path/linksearch3?cdColaborador=7442',
> _response: 'unexpected end of stream',
> _url: 'http://myip.com:8080/myapi/path/linksearch3?cdColaborador=7442',
> _timedOut: false,
> _trackingName: 'unknown',
> _incrementalEvents: false,
> _performanceLogger:
> { _timespans:
> { 'network_XMLHttpRequest_http://myip.com:8080/rest-api/auth':
> { startTime: 8630575.8016,
> startExtras: undefined,
> endExtras: undefined,
> endTime: 8630951.7208,
> totalTime: 375.91919999942183 },
> 'network_XMLHttpRequest_http://myip.com:8080/path/linkserach1':
> { startTime: 8631528.126,
> startExtras: undefined,
> endExtras: undefined,
> endTime: 8631973.0137,
> totalTime: 444.8876999989152 },
> 'network_XMLHttpRequest_http://myip.com:8080/path/linksearch2':
> { startTime: 8632033.7623,
> startExtras: undefined,
> endExtras: undefined,
> endTime: 8632421.9302,
> totalTime: 388.16789999976754 },
> 'network_XMLHttpRequest_http://myip.com:8080/path/linksearch3':
> { startTime: 8632478.1932,
> startExtras: undefined,
> endExtras: undefined,
> endTime: 8656735.1845,
> totalTime: 24256.991299999878 },
> 'network_XMLHttpRequest_http://myip.com:8080/path/linksearch4':
> { startTime: 8660848.4174,
> startExtras: undefined,
> endExtras: undefined,
> endTime: 8661277.8728,
> totalTime: 429.455399999395 },
> 'network_XMLHttpRequest_http://myip.com:8080/path/linksearch5':
> { startTime: 8661367.8179,
> startExtras: undefined,
> endExtras: undefined,
> endTime: 8662393.9181,
> totalTime: 1026.1001999992877 },
> 'network_XMLHttpRequest_http://myip.com:8080/myapi/path/linksearch3?cdColaborador=7442':
> { startTime: 8662680.029, startExtras: undefined } },
> _extras: {},
> _points:
> { initializeCore_start: 64197.2119,
> initializeCore_end: 64461.4723 },
> _pointExtras: {},
> _closed: false },
> responseHeaders: undefined,
> _requestId: null,
> _cachedResponse: undefined,
> _headers:
> { accept: '*/*',
> 'x-session-id': 'my-session-id-1234',
> 'accept-encoding': 'gzip, deflate, br',
> connection: 'keep-alive' },
> _responseType: '',
With "Postman" I'm able to receive the response normally, it takes about 30 seconds to receive the response.
My request code:
import axios from 'axios';
import apiConfig from './apiAuth/config';
import {getAccessToken} from '../services/apiAuth/tokenClient';
const apiClient = axios.create({
baseURL: apiConfig.baseUrl,
timeout: 0,
maxContentLength: Infinity,
maxBodyLength: Infinity,
headers: {
'Content-Type': 'application/json',
Accept: '*/*',
'Accept-Encoding': 'gzip, deflate, br',
Connection: 'keep-alive',
},
});
export {apiClient};
My Realm import code (works for all other requests):
requestPrices = async (httpClient) => {
let itens = null;
await httpClient
.get(apiConfig.url_prices)
.then((response) => {
itens = response.data;
return new Promise((resolve) => {
if (itens) {
const databaseOptions = {allSchemas};
Realm.open(databaseOptions).then((realm) => {
realm.write(() => {
if (itens) {
const resolveItens = itens.prices.map(async (obj, k) => {
console.log('inserting price of item = ', k);
return await realm.create('Price', obj, true);
});
Promise.all(resolveItens).then(() => resolve(true));
} else {
console.log('itens: ', itens);
}
});
});
} else {
resolve(true);
}
});
})
.catch((error) => {
console.log(error);
Alertmsg.danger('Price: ' + Const.SYNC_DATA_ERROR);
});
Please, someone can Help Me!
