DERA chain docs
  • Introduction
  • NFT2.0
    • Introduction
    • Architecture
    • Concepts
      • Collection
      • NFT2.0
      • Data Registry
      • Derivative NFT
      • Derived Account
      • Token Bound Account (aka TBA)
    • Smart Contracts
      • Interfaces
        • Factory
        • Dynamicity
        • Derivability
        • Cross chain ability
      • Use cases
        • Create collection
        • Mint NFT2.0
        • Create Data registry
        • Write onchain data
        • Retrieve onchain data
        • Mint Derivative NFT2.0
        • Create TBA
    • SDK
      • Setup
        • Create Console Account
        • Manage API key
        • Set up metadata schema
        • Initialize the SDK
      • API reference
        • Get List Collection
        • Get List Collection By Owner
        • Get Collection Info
        • Get List NFT By Collection
        • Get List NFT By Owner
        • Get List Derivative NFT By Original
        • Get NFT Info
        • Get List Data Registry
        • Get Data Registry By Owner
        • Get Data Registry Info
        • Get NFT onchain data
        • Get NFT protocol-scoped onchain data
        • Get User Freemint Info
        • Get Claim Token Uri Info
        • Upload JSON Uri Data To IPFS
        • Generate Presigned URL To Upload Image (IPFS)
        • Utility Functions
    • App guide
      • NFT2Scan
        • Create Collection
        • Mint NFT2.0
        • Mint Derivative NFT2.0
      • NFT2Console
        • Create Dapp
        • Register data schema
        • Manage API keys
        • Manage onchain data
    • References
      • Links
  • Bridge
    • Introduction
    • Bridge Token
    • Bridge NFT
  • Staking
    • Introduction
    • Validate
    • Delegate
  • Smart Contracts
    • EVM compatibility
    • Hardhat
    • Foundry
    • Account Abstraction
    • SubQuery Indexer
    • SAFE multisign
  • Nodes & Validators
    • Run a Node
    • Become a Validator
Powered by GitBook
On this page
  • Request
  • Parameters
  • Response
  • Using presigned URL to upload image to S3
  1. NFT2.0
  2. SDK
  3. API reference

Generate Presigned URL To Upload Image (IPFS)

Request

In order to get a presigned url to upload image to IPFS, SDK provides you with a generatePresignedImage endpoint to do so

try {
  const apiProtocol = nft2Client.getAPIService();
 
  const presignedList = await apiProtocol.generatePresignedImage({
    files: [
      {
        fileName: 'file1.png',
        mimeType: 'image/png',
      },
      {
        fileName: 'file2.jpeg',
        mimeType: 'image/jpeg',
      },
      ...
    ]
  });
 
  console.log(presignedList)
} catch (e) {
  console.error(e);
}

Parameters

  • Params type: PresignImageData

  • files (Array): Array of presign image metadata (fileName and mimeType).

(!) To ensure IPFS service performance and avoid rate limit when upload files, size of array files must be <= 50.

(!) Image mimeType only support in ["image/png", "image/jpeg", "image/svg+xml"]

Response

{
  urls: [
    "https://nft2-protocol.s3.filebase.com/file1-xxx.png?SIGNED_DATA&x-id=PutObject",
    "https://nft2-protocol.s3.filebase.com/file2-xxx.jpeg?SIGNED_DATA&x-id=PutObject",
    ...
  ];
}
Maybe some HTTP Exception

Using presigned URL to upload image to S3

try {
  const presignedUrl = "..." // get from generatePresignedImage
  const file = "..." // file object or data arraybuffer
 
  const response = await axios.put(presignedUrl, file, {
    headers: {
      "Content-Type": file.type || "image/png", // mimeType
    },
  })
 
  const imageData = {
    image_name: file.name,
    image_cid: response.headers?.["x-amz-meta-cid"], // CID of image on IPFS
  }
 
  console.log(imageData)
} catch (e) {
  console.error(e);
}
PreviousUpload JSON Uri Data To IPFSNextUtility Functions

Last updated 7 months ago