import { Web3Storage } from 'web3.storage'const client = new Web3Storage({ token: apiToken })
Store files using the put()
method.
<clientObject>.put(file[], { options })
In the browser, using a file chooser to prompt the user for files to store:
const fileInput = document.querySelector('input[type="file"]')const rootCid = await client.put(fileInput.files, { name: 'cat pics',
The method returns a string containing the CID of the uploaded CAR.
Method parameters are supplied in positional order.
An {options}
object has the following properties that can be used as parameters when calling put()
:
Retrieve files using the get()
method. You will need the CID you obtained at upload time that references the CAR for your uploaded files.
Returns undefined
if there are no matches for the given CID.
If found, the method returns a Web3Response
object, which extends the Fetch API response object to add two iterator methods unique to the Web3.Storage client library: files()
and unixFsIterator()
.