@ardrive/turbo-sdk 1.27.0-alpha.4 → 1.27.0
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/README.md +38 -20
- package/bundles/web.bundle.min.js +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -567,32 +567,25 @@ const uploadResult = await turbo.upload({
|
|
567
567
|
});
|
568
568
|
```
|
569
569
|
|
570
|
-
#### `uploadFile({
|
570
|
+
#### `uploadFile({ ...fileOrStreamFactoryOpts, signal, dataItemOpts, events })`
|
571
571
|
|
572
|
-
Signs and uploads a raw file.
|
572
|
+
Signs and uploads a raw file. There are two ways to provide the file to the SDK:
|
573
|
+
|
574
|
+
1. Using a `file` parameter
|
575
|
+
2. Using a `fileStreamFactory` and `fileSizeFactory`
|
576
|
+
|
577
|
+
##### Using `file`
|
578
|
+
|
579
|
+
In Web with a file input:
|
573
580
|
|
574
581
|
```typescript
|
575
|
-
const
|
576
|
-
const fileSize = fs.stateSync(filePath).size;
|
582
|
+
const selectedFile = e.target.files[0];
|
577
583
|
const uploadResult = await turbo.uploadFile({
|
578
|
-
|
579
|
-
fileSizeFactory: () => fileSize,
|
584
|
+
file: selectedFile,
|
580
585
|
dataItemOpts: {
|
581
|
-
|
582
|
-
tags: [
|
583
|
-
{
|
584
|
-
name: 'Content-Type',
|
585
|
-
value: 'text/plain',
|
586
|
-
},
|
587
|
-
{
|
588
|
-
name: 'My-Custom-Tag',
|
589
|
-
value: 'my-custom-value',
|
590
|
-
},
|
591
|
-
],
|
592
|
-
// no timeout or AbortSignal provided
|
586
|
+
tags: [{ name: 'Content-Type', value: 'text/plain' }],
|
593
587
|
},
|
594
588
|
events: {
|
595
|
-
// upload events
|
596
589
|
onUploadProgress: ({ totalBytes, processedBytes }) => {
|
597
590
|
console.log('Upload progress:', { totalBytes, processedBytes });
|
598
591
|
},
|
@@ -602,11 +595,36 @@ const uploadResult = await turbo.uploadFile({
|
|
602
595
|
onUploadSuccess: () => {
|
603
596
|
console.log('Upload success!');
|
604
597
|
},
|
605
|
-
// add any other events you want to listen to (see `Events` section for more details)
|
606
598
|
},
|
607
599
|
});
|
608
600
|
```
|
609
601
|
|
602
|
+
In NodeJS with a file path:
|
603
|
+
|
604
|
+
```typescript
|
605
|
+
const filePath = path.join(__dirname, './my-unsigned-file.txt');
|
606
|
+
const fileSize = fs.stateSync(filePath).size;
|
607
|
+
const uploadResult = await turbo.uploadFile({
|
608
|
+
file: filePath,
|
609
|
+
dataItemOpts: {
|
610
|
+
tags: [{ name: 'Content-Type', value: 'text/plain' }],
|
611
|
+
},
|
612
|
+
});
|
613
|
+
```
|
614
|
+
|
615
|
+
##### Using `fileStreamFactory` and `fileSizeFactory`
|
616
|
+
|
617
|
+
Note: The provided `fileStreamFactory` should produce a NEW file data stream each time it is invoked. The `fileSizeFactory` is a function that returns the size of the file. The `signal` is an optional [AbortSignal] that can be used to cancel the upload or timeout the request. `dataItemOpts` is an optional object that can be used to configure tags, target, and anchor for the data item upload.
|
618
|
+
|
619
|
+
```typescript
|
620
|
+
const filePath = path.join(__dirname, './my-unsigned-file.txt');
|
621
|
+
const fileSize = fs.stateSync(filePath).size;
|
622
|
+
const uploadResult = await turbo.uploadFile({
|
623
|
+
fileStreamFactory: () => fs.createReadStream(filePath),
|
624
|
+
fileSizeFactory: () => fileSize,
|
625
|
+
});
|
626
|
+
```
|
627
|
+
|
610
628
|
#### `uploadFolder({ folderPath, files, dataItemOpts, signal, maxConcurrentUploads, throwOnFailure, manifestOptions })`
|
611
629
|
|
612
630
|
Signs and uploads a folder of files. For NodeJS, the `folderPath` of the folder to upload is required. For the browser, an array of `files` is required. The `dataItemOpts` is an optional object that can be used to configure tags, target, and anchor for the data item upload. The `signal` is an optional [AbortSignal] that can be used to cancel the upload or timeout the request. The `maxConcurrentUploads` is an optional number that can be used to limit the number of concurrent uploads. The `throwOnFailure` is an optional boolean that can be used to throw an error if any upload fails. The `manifestOptions` is an optional object that can be used to configure the manifest file, including a custom index file, fallback file, or whether to disable manifests altogether. Manifests are enabled by default.
|
@@ -314072,7 +314072,7 @@ var import_winston = __toESM(require_winston(), 1);
|
|
314072
314072
|
init_dirname();
|
314073
314073
|
init_buffer2();
|
314074
314074
|
init_process2();
|
314075
|
-
var version16 = "1.27.0-alpha.
|
314075
|
+
var version16 = "1.27.0-alpha.4";
|
314076
314076
|
|
314077
314077
|
// src/common/logger.ts
|
314078
314078
|
var TurboWinstonLogger = class _TurboWinstonLogger {
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/version.js
CHANGED
package/lib/types/version.d.ts
CHANGED