From 834e5bd1637e6dbfe6d0ea100a116153399c0ef1 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Thu, 15 Aug 2024 12:08:54 +0200 Subject: [PATCH] Send the file directly without splitting it into chunks in order to let the HTTP protocol handle the file itself. --- src/chunks/chunks.ts | 19 ------------------- src/data/data.ts | 28 +++++++++++++--------------- 2 files changed, 13 insertions(+), 34 deletions(-) delete mode 100644 src/chunks/chunks.ts diff --git a/src/chunks/chunks.ts b/src/chunks/chunks.ts deleted file mode 100644 index 371abda..0000000 --- a/src/chunks/chunks.ts +++ /dev/null @@ -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; - }, -}; diff --git a/src/data/data.ts b/src/data/data.ts index 2859da2..57b6407 100644 --- a/src/data/data.ts +++ b/src/data/data.ts @@ -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) {