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",
},
];