@@ -26,6 +26,34 @@ To interact with the Auto-Drive API, you'll need to create an API key. Follow th
2626- Once you're logged in, click on the developers section in the left sidebar menu.
2727- In the developers section, click on 'Create API Key'
2828- Read the modal message and click on generate
29+ Add
30+ ### How to upload a file from Buffer?
31+
32+ Here is an example of how to use the ` uploadFileFromBuffer ` method to upload a Buffer with optional encryption and compression:
33+
34+ ``` typescript
35+ import { createAutoDriveApi } from ' @autonomys/auto-drive'
36+ import { NetworkId } from ' @autonomys/auto-utils'
37+
38+ const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .MAINNET }) // Initialize your API instance with API key
39+
40+ // Create a buffer from your data
41+ const buffer = Buffer .from (' Hello, Autonomys!' )
42+ const fileName = ' hello.txt'
43+
44+ const options = {
45+ password: ' your-encryption-password' , // Optional: specify a password for encryption
46+ compression: true ,
47+ // an optional callback useful for large file uploads
48+ onProgress?: (progress : number ) => {
49+ console .log (` The upload is ${progress }% completed ` )
50+ }
51+ }
52+
53+ const cid = await api .uploadFileFromBuffer (buffer , fileName , options )
54+
55+ console .log (` The file is uploaded and its cid is ${cid } ` )
56+ ```
2957
3058### How to upload a file from filepath? (Not available in browser)
3159
@@ -35,7 +63,7 @@ Here is an example of how to use the `fs.uploadFileFromFilepath` method to uploa
3563import { fs , createAutoDriveApi } from ' @autonomys/auto-drive'
3664import { NetworkId } from ' @autonomys/auto-utils'
3765
38- const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .TAURUS }) // Initialize your API instance with API key
66+ const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .MAINNET }) // Initialize your API instance with API key
3967const filePath = ' path/to/your/file.txt' // Specify the path to your file
4068const options = {
4169 password: ' your-encryption-password' , // Optional: specify a password for encryption
@@ -57,7 +85,7 @@ console.log(`The file is uploaded and its cid is ${cid}`)
5785import { createAutoDriveApi } from ' @autonomys/auto-drive'
5886import { NetworkId } from ' @autonomys/auto-utils'
5987
60- const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .TAURUS }) // Initialize your API instance with API key
88+ const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .MAINNET }) // Initialize your API instance with API key
6189
6290// e.g Get File from object from HTML event
6391const file: File = e .target .value // Substitute with your file
@@ -92,7 +120,7 @@ You could upload any file that could be represented in that way. For example, up
92120import { createAutoDriveApi } from ' @autonomys/auto-drive'
93121import { NetworkId } from ' @autonomys/auto-utils'
94122
95- const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .TAURUS }) // Initialize your API instance with API key
123+ const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .MAINNET }) // Initialize your API instance with API key
96124const buffer = Buffer .from (... );
97125const genericFile = {
98126 read : async function * () {
@@ -124,7 +152,7 @@ console.log(`The file is uploaded and its cid is ${cid}`)
124152import { createAutoDriveApi , fs } from ' @autonomys/auto-drive'
125153import { NetworkId } from ' @autonomys/auto-utils'
126154
127- const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .TAURUS }) // Initialize your API instance with API key
155+ const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .MAINNET }) // Initialize your API instance with API key
128156const folderPath = ' path/to/your/folder' // Specify the path to your folder
129157
130158const options = {
@@ -151,7 +179,7 @@ Here is an example of how to use the `downloadFile` method to download a file fr
151179import { createAutoDriveApi } from ' @autonomys/auto-drive'
152180import { NetworkId } from ' @autonomys/auto-utils'
153181
154- const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .TAURUS }) // Initialize your API instance with API key
182+ const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .MAINNET }) // Initialize your API instance with API key
155183
156184try {
157185 const cid = ' ..'
@@ -176,7 +204,7 @@ Here are examples of how to use the object moderation methods:
176204import { createAutoDriveApi } from ' @autonomys/auto-drive'
177205import { NetworkId } from ' @autonomys/auto-utils'
178206
179- const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .TAURUS })
207+ const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .MAINNET })
180208
181209try {
182210 const cid = ' your-object-cid'
@@ -193,7 +221,7 @@ try {
193221import { createAutoDriveApi } from ' @autonomys/auto-drive'
194222import { NetworkId } from ' @autonomys/auto-utils'
195223
196- const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .TAURUS })
224+ const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .MAINNET })
197225
198226try {
199227 const cid = ' your-object-cid'
@@ -210,7 +238,7 @@ try {
210238import { createAutoDriveApi } from ' @autonomys/auto-drive'
211239import { NetworkId } from ' @autonomys/auto-utils'
212240
213- const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .TAURUS })
241+ const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .MAINNET })
214242
215243try {
216244 const cid = ' your-object-cid'
@@ -227,7 +255,7 @@ try {
227255import { createAutoDriveApi } from ' @autonomys/auto-drive'
228256import { NetworkId } from ' @autonomys/auto-utils'
229257
230- const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .TAURUS })
258+ const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .MAINNET })
231259
232260try {
233261 const toBeReviewed = await api .getToBeReviewedList (50 , 0 )
@@ -248,7 +276,7 @@ Here is an example of how to use the `publishObject` method to publish an object
248276import { createAutoDriveApi } from ' @autonomys/auto-drive'
249277import { NetworkId } from ' @autonomys/auto-utils'
250278
251- const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .TAURUS }) // Initialize your API instance with API key
279+ const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .MAINNET }) // Initialize your API instance with API key
252280
253281try {
254282 const cid = ' your-file-cid'
@@ -269,7 +297,7 @@ Here is an example of how to use the `getMyFiles` method to retrieve the root di
269297import { createAutoDriveApi } from ' @autonomys/auto-drive'
270298import { NetworkId } from ' @autonomys/auto-utils'
271299
272- const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .TAURUS }) // Initialize your API instance with API key
300+ const api = createAutoDriveApi ({ apiKey: ' your-api-key' , network: NetworkId .MAINNET }) // Initialize your API instance with API key
273301
274302try {
275303 for (let i = 0 ; i < 10 ; i ++ ) {
0 commit comments