@centia-io/sdk 0.0.51 → 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.
@@ -2131,23 +2131,48 @@
2131
2131
  }
2132
2132
  /**
2133
2133
  * Upload a file via multipart/form-data.
2134
- * In Node.js, pass a FormData instance. In browsers, pass a native FormData.
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({
2147
2172
  path: "api/v4/file/process",
2148
2173
  method: "POST",
2149
2174
  body,
2150
- expectedStatus: 200
2175
+ expectedStatus: 201
2151
2176
  });
2152
2177
  }
2153
2178
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centia-io/sdk",
3
- "version": "0.0.51",
3
+ "version": "0.0.53",
4
4
  "description": "Centia-io TypeScript SDK",
5
5
  "author": "Martin Høgh",
6
6
  "license": "MIT",