@igorvaryvoda/sirv-upload-widget 0.1.6 → 0.1.8

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/index.mjs CHANGED
@@ -1368,21 +1368,14 @@ function useSirvUpload(options) {
1368
1368
  if (!proxyEndpoint) throw new Error("No proxy endpoint configured");
1369
1369
  if (!file.file) throw new Error("No file data");
1370
1370
  updateFile(file.id, { status: "uploading", progress: 10 });
1371
- const arrayBuffer = await file.file.arrayBuffer();
1372
- const base64 = btoa(
1373
- new Uint8Array(arrayBuffer).reduce((data, byte) => data + String.fromCharCode(byte), "")
1374
- );
1371
+ const uploadUrl = new URL(`${proxyEndpoint}/upload`);
1372
+ uploadUrl.searchParams.set("filename", file.filename);
1373
+ uploadUrl.searchParams.set("folder", folder);
1375
1374
  updateFile(file.id, { progress: 30 });
1376
- const res = await fetch(`${proxyEndpoint}/upload`, {
1375
+ const res = await fetch(uploadUrl.toString(), {
1377
1376
  method: "POST",
1378
- headers: { "Content-Type": "application/json" },
1379
- body: JSON.stringify({
1380
- data: base64,
1381
- filename: file.filename,
1382
- folder,
1383
- contentType: getMimeType(file.file),
1384
- onConflict: onConflict === "ask" ? "rename" : onConflict
1385
- }),
1377
+ headers: { "Content-Type": getMimeType(file.file) },
1378
+ body: file.file,
1386
1379
  signal
1387
1380
  });
1388
1381
  updateFile(file.id, { progress: 80 });
@@ -1401,7 +1394,7 @@ function useSirvUpload(options) {
1401
1394
  sirvPath: result.path
1402
1395
  });
1403
1396
  },
1404
- [proxyEndpoint, folder, onConflict, updateFile]
1397
+ [proxyEndpoint, folder, updateFile]
1405
1398
  );
1406
1399
  const uploadFile = useCallback(
1407
1400
  async (id) => {