codecamp

Moralis Web3API.storage (IPFS)

uploadFolder(新)

上传多个文件并将它们放在一个文件夹目录中。 返回路径(异步)。

选项:

  • abi​(必需):支持 JSON 和 Base64 的数组

你可以使用​JS​、​React​、​curl​、​Unity​来实现

const options = {
  abi: [
    {
      path: "moralis/logo.jpg",
      content:
        "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3",
    },
  ],
};
const path = await Moralis.Web3API.storage.uploadFolder(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";

const Web3Api = useMoralisWeb3Api();

const uploadFolder = async () => {
  const options = {
    abi: [
      {
        path: "moralis/logo.jpg",
        content:
          "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3",
      },
    ],
  };
  const path = await Web3Api.storage.uploadFolder(options);
  console.log(path);
};
curl -X 'POST' \
  'https://deep-index.moralis.io/api/v2/ipfs/uploadFolder' \
  -H 'accept: application/json' \
  -H 'X-API-Key: MY-API-KEY' \
  -H 'Content-Type: application/json' \
  -d '[
  {
    "path": "moralis/logo.jpg",
    "content": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3"
  }
]'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;


  public async void fetchPairReserves()
  {
     // Define file information.
      IpfsFileRequest req = new IpfsFileRequest()
      {
        Path = "moralis/logo.jpg",
        Content = "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3"
      };
      // Multiple requests can be sent via a List so define the request list.
      List<IpfsFileRequest> reqs = new List<IpfsFileRequest>();
      // Add requests to request list.
      reqs.Add(req);
      List<IpfsFile> resp = await web3Api.Storage.UploadFolder(reqs);
      foreach (IpfsFile file in resp)
      {
        print(file.ToJson());
      }
  }

示例结果

[
  {
    path: "https://ipfs.moralis.io/QmPQ3YJ3hgfsBzJ1U4MGyV2C1GhDy6MWCENr1qMdMpKVnY/moralis/logo.jpg",
  },
];


Moralis Web3API.defi
Moralis Web3API.resolve
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Moralis 文件

Moralis 工具

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }