When a file is loaded with a volume of more than 600MB, it turns out to be empty. The backend completely unloads the file. Used by Axios. Used downloadjs lib for download. I used a lot of lib who likes downloadjs and the result was the same. How can I implement uploading a large file using Axios ?
response
{data: 'Id;Email;ClientDwhId;Number;16_int;22_datetime;22… headers: {…}, cancelTokenSource: {…}}
cancelTokenSource:
cancel: ƒ cancel(message)
token: CancelToken
promise: Promise
[[Prototype]]: Promise
[[PromiseState]]: "pending"
[[PromiseResult]]: undefined
[[Prototype]]: Object
[[Prototype]]: Object
data: "Id;Email;ClientDwhId;Number;16_int;22_datetime;2
headers:
content-disposition: "attachment; filename=File.csv; filename*=UTF-8''File.csv"
content-length: "42277"
content-type: "text/csv"
[[Prototype]]: Object
[[Prototype]]: Object
import * as contentDisposition from 'content-disposition';
import * as downloadjs from 'downloadjs';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { ApiResponse } from '../api';
const defaultContentType = 'text/plain';
const defaultFilename = 'file.txt';
const downloadFile = (response: ApiResponse<BlobPart>, filename?: string) => {
//create filename
if (!filename) {
const parsedContentDisposition =
response.headers['content-disposition'] &&
contentDisposition.parse(response.headers['content-disposition']);
filename =
parsedContentDisposition && parsedContentDisposition.parameters
? parsedContentDisposition.parameters.filename
: defaultFilename;
}
//create content type
const contentType = response.headers['content-type']
? response.headers['content-type']
: defaultContentType;
//function from downloadjs library
downloadjs(
new Blob([response.data]), filename, contentType,);
};
export const downloadFileFromStream = (filename?: string) => (
stream$: Observable<ApiResponse<BlobPart>>,
) => stream$.pipe(tap(response => downloadFile(response, filename))); //run downloadFile function after response
We solved the problem on the server side. They began to save the file on the server and send it by reference, without loading the user with a stream.