Send the file directly without splitting it into chunks in order to let the HTTP protocol handle the file itself.

This commit is contained in:
Arnaud 2024-08-15 12:08:54 +02:00
parent f5dd224479
commit 834e5bd163
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
2 changed files with 13 additions and 34 deletions

View File

@ -1,19 +0,0 @@
export const Chunks = {
async split(file: File) {
const totalSize = file.size;
const chunkSize = 1024 * 1024 * 3; // 10MB
const chunks = [] as Uint8Array[];
const amountOfChunks = Math.ceil(totalSize / chunkSize);
for (let index = 0; index < amountOfChunks; index++) {
const start = index * chunkSize;
const end = (index + 1) * chunkSize;
const chunk = await file.slice(start, end).arrayBuffer();
chunks.push(new Uint8Array(chunk));
}
return chunks;
},
};

View File

@ -1,5 +1,5 @@
import { Api } from "../api/config";
import { Chunks } from "../chunks/chunks";
/*import { Chunks } from "../chunks/chunks";*/
import { Fetch } from "../fetch-safe/fetch-safe";
import type { SafeValue } from "../values/values";
import type { CodexDataResponse, CodexNodeSpace } from "./types";
@ -30,17 +30,17 @@ export class Data {
return data;
}
/* const mimetypes = [
"image/png",
"image/jpg",
"image/jpeg",
"audio/mp3",
"video/mp4",
"application/pdf",
"application/msdoc",
"text/plain",
];
*/
/* const mimetypes = [
"image/png",
"image/jpg",
"image/jpeg",
"audio/mp3",
"video/mp4",
"application/pdf",
"application/msdoc",
"text/plain",
];*/
return {
error: false,
data: {
@ -102,9 +102,7 @@ export class Data {
xhr.open("POST", url, true);
await Chunks.split(file);
xhr.send(new Blob(await Chunks.split(file)));
xhr.send(file);
xhr.onload = function () {
if (xhr.status != 200) {