Releases: spheronFdn/sdk
Releases · spheronFdn/sdk
core:1.0.3
Updated
- Update the
UsageWithLimits
interface. Removed theusedStorageFileCoin
properties and added theusedParallelUploads
.
storage:v1.0.14
Changed
- Improved the propagation of errors.
core:1.0.2
Changed
- Improved the error handling so that the error is propagated when uploading payloads.
browser-upload:v1.0.1
Changed
- Improved the propagation of errors.
cli: v1.0.9
Updated
- Update the name of
my-NFTCollection-claimer
template toLYNC-claimer-page
.
cli: v1.0.8
Added
- Added new
LYNC NFT Collection Claimer
dapp template.
storage:v1.0.13
Changed
- Moved all the logic that is shared between the packages, to the
@spheron/core
package, and update the@spheron/storage
to use it. - Added a new method
async createSingleUploadToken(configuration: { name: string; protocol: ProtocolEnum; }): Promise<{ uploadToken: string }>
- used to create a token for the @spheron/browser-upload package. The token can be used by your web app to enable users to directly upload their data from their browser to the specified protocol. Checkout the @spheron/browser-upload package for more information.
core:1.0.1
Changed
- Moved the
UploadManager
class from the@spheron/storage
package to the@spheron/core
package. - Moved the methods that only existed in the
@spheron/storage
SpheronApi class to the@spheron/core
, so that@spheron/storage
can use the@spheron/core
package.
browser-upload:v1.0.0
Browser Upload
Usage:
This package adds support to upload files directly from browser to IPFS, Filecoin or Arweave via Spheron.
The general usage flow would be as:
- Send a request from your web app to your BE service to generate a token that can be used only for a single upload. In this request you can check if the user of you app has all the requirements to upload data.
// Send a request to your Backend endpoint to create a token that will be used with the @spheron/browser-upload
const response = await fetch(`<BACKEND_URL>/initiate-upload`);
- On your BE service, use the method
createSingleUploadToken
from @spheron/storage package. This method will provide you with a unique token that can only be used for a single upload with theupload
function from @spheron/browser-upload, and this token has a expiration of 10 minutes.
import { SpheronClient, ProtocolEnum } from "@spheron/storage";
...
app.get("/initiate-upload", async (req, res, next) => {
try {
const bucketName = "example-browser-upload"; // use which ever name you prefer
const protocol = ProtocolEnum.IPFS; // use which ever protocol you prefer
const client = new SpheronClient({
token: <SPHERON_TOKEN>,
});
const { uploadToken } = await client.createSingleUploadToken({
name: bucketName,
protocol,
});
res.status(200).json({
uploadToken,
});
} catch (error) {
console.error(error);
next(error);
}
});
- Return to your web app the token you got from
createSingleUploadToken
, and usingupload
method from @spheron/browser-upload, upload files directly from the Browser to the specified protocol.
import { upload } from "@spheron/browser-upload";
...
const response = await fetch(`<BACKEND_URL>/initiate-upload`); // from step 1
const resJson = await response.json();
const token = resJson.uploadToken;
const uploadResult = await upload(<FILES_YOU_WANT_TO_UPLOAD>, { token });
...
Using this flow, you can control who can use you API token and upload data from your web app.
Checkout the LINK for a working example.
Example:
import { upload } from "@spheron/browser-upload";
const uploadToken = /* logic that would send a request to your BE and return a token that can be used only for a single upload */
let currentlyUploaded = 0;
const uploadResult = await upload(files, {
token: res.uploadToken,
onChunkUploaded: (uploadedSize, totalSize) => {
currentlyUploaded += uploadedSize;
console.log(`Uploaded ${currentlyUploaded} of ${totalSize} Bytes.`);
},
});
- The package exports one function
upload(files: File[], configuration: { token: string; onChunkUploaded?: (uploadedSize: number, totalSize: number) => void; }): Promise<UploadResult>
- Function
upload
has two parametersclient.upload(filePath, configuration);
files
- files that will be uploaded.configuration
- an object with parameters:configuration.token
- a token used for a single upload. Check the Access Token section bellow for more information.configuration.onChunkUploaded
- optional - callback function(uploadedSize: number, totalSize: number) => void
. The function will be called multiple times, depending on the upload size. The function will be called each time a chunk is uploaded, with two parameters. the first oneuploadedSize
represents the size in Bytes for the uploaded chunk. ThetotalSize
represents the total size of the upload in Bytes.
- The response of the upload function is an object with parameters:
uploadId
- the id of the upload.bucketId
- the id of the bucket.protocolLink
- the protocol link of the upload.dynamicLinks
- domains that you have setup for your bucket. When you upload new data to the same bucket, the domains will point to the new uploaded data.
- Function
Access Token
To create a token you should use the method createSingleUploadToken
from @spheron/storage package on you Backend service. This method will generate a unique token that can be used only for a single upload.
Notes
The package is only meant for Browser environments.
Learn More
You can learn more about Spheron and browser-upload package here:
storage:v1.0.12
Added
- Added two new methods for converting CID from V0 to V1, and vice verse.
import { ipfs } from "@spheron/storage";
const cid = <CID_VALUE>;
const v1 = ipfs.utils.toV1(cid);
console.log("CID V1", v1);
const v0 = ipfs.utils.toV0(cid);
console.log("CID V0", v0);
- Added an IPNS example
Changed
- renamed method
getIPNSNamesForDeployment
togetIPNSNamesForUpload