@centia-io/sdk 0.0.52 → 0.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/centia-io-sdk.cjs +28 -3
- package/dist/centia-io-sdk.d.cts +7 -3
- package/dist/centia-io-sdk.d.cts.map +1 -1
- package/dist/centia-io-sdk.d.ts +7 -3
- package/dist/centia-io-sdk.d.ts.map +1 -1
- package/dist/centia-io-sdk.js +28 -3
- package/dist/centia-io-sdk.js.map +1 -1
- package/dist/centia-io-sdk.umd.js +28 -3
- package/package.json +1 -1
|
@@ -2131,16 +2131,41 @@
|
|
|
2131
2131
|
}
|
|
2132
2132
|
/**
|
|
2133
2133
|
* Upload a file via multipart/form-data.
|
|
2134
|
-
*
|
|
2134
|
+
* When `options.chunkSize` is set, the file is split into chunks and uploaded
|
|
2135
|
+
* sequentially. The server reassembles the file from the chunks.
|
|
2135
2136
|
*/
|
|
2136
|
-
async postFileUpload(formData) {
|
|
2137
|
-
return this.client.request({
|
|
2137
|
+
async postFileUpload(formData, options) {
|
|
2138
|
+
if (!options?.chunkSize) return this.client.request({
|
|
2138
2139
|
path: "api/v4/file/upload",
|
|
2139
2140
|
method: "POST",
|
|
2140
2141
|
body: formData,
|
|
2141
2142
|
contentType: null,
|
|
2142
2143
|
expectedStatus: 201
|
|
2143
2144
|
});
|
|
2145
|
+
const file = formData.get("filename");
|
|
2146
|
+
if (!file) throw new Error("FormData must contain a \"filename\" entry for chunked upload.");
|
|
2147
|
+
const fileName = file instanceof File ? file.name : "upload";
|
|
2148
|
+
const totalChunks = Math.ceil(file.size / options.chunkSize);
|
|
2149
|
+
let result = { filename: "" };
|
|
2150
|
+
for (let i = 0; i < totalChunks; i++) {
|
|
2151
|
+
const start = i * options.chunkSize;
|
|
2152
|
+
const end = Math.min(start + options.chunkSize, file.size);
|
|
2153
|
+
const chunk = file.slice(start, end);
|
|
2154
|
+
const chunkForm = new FormData();
|
|
2155
|
+
chunkForm.append("filename", chunk, fileName);
|
|
2156
|
+
result = await this.client.request({
|
|
2157
|
+
path: "api/v4/file/upload",
|
|
2158
|
+
method: "POST",
|
|
2159
|
+
body: chunkForm,
|
|
2160
|
+
contentType: null,
|
|
2161
|
+
query: {
|
|
2162
|
+
chunk: String(i),
|
|
2163
|
+
chunks: String(totalChunks)
|
|
2164
|
+
},
|
|
2165
|
+
expectedStatus: 201
|
|
2166
|
+
});
|
|
2167
|
+
}
|
|
2168
|
+
return result;
|
|
2144
2169
|
}
|
|
2145
2170
|
async postFileProcess(body) {
|
|
2146
2171
|
return this.client.request({
|