gpt4 book ai didi

python - 将目录上传到 pinata ipfs API

转载 作者:行者123 更新时间:2023-12-05 05:50:42 31 4
gpt4 key购买 nike

我正在尝试将 png 目录上传到 pinata,但我一直收到此错误:

{'error': 'Invalid file path: C:\\Users\\myname\\Documents\\Coding Projects\\nft\\art\\reveal\\1.png detected. 
If you are receiving this, you provided either bad data or a file path our systems have
flagged as unsafe for processing. If your file paths are valid, please contact us at
team@pinata.cloud. We would love to help accommodate your needs!'}

这是我试过的代码:


def get_all_files(directory: str) -> tp.List[str]:
"""get a list of absolute paths to every file located in the directory"""
paths: tp.List[str] = []
for root, dirs, files_ in os.walk(os.path.abspath(directory)):
for file in files_:
paths.append(os.path.join(root, file))
return paths

def upload_directory_to_pinata(directory):

all_files: tp.List[str] = get_all_files(directory)
files = [("file", (file, open(file, "rb"))) for file in all_files]

print(files)

headers = {
"pinata_api_key": os.getenv("PINATA_API_KEY"),
"pinata_secret_api_key": os.getenv("PINATA_API_SECRET"),
}

response = requests.Response = requests.post(
url=PINATA_BASE_URL + endpoint, files=files, headers=headers
)

data = response.json()
print(data)
imageLinkBase = "ipfs://" + data["IpfsHash"] + "/"
return imageLinkBase

该文件路径确实是一个有效的文件路径。我需要一个带有 CID 的 IPFS(或 pinata)目录,然后在里面放一堆数字图片。如果有任何其他方法可以做到这一点,lmk!谢谢!

最佳答案

也许您添加了每个文件的绝对路径而不是相对文件路径?

This endpoint also allows users to pin an entire directory to IPFS. 
This works almost identically to pinning a file, with the main difference being that we provide
an array of files and need to provide a relative file path for each file in the directory.

However, our servers will use the exact path that's provided for each file,
so it's important that each path begins with the "base" directory that is being uploaded.
As an example, if your directory is located at "./../myBuilds/desiredBuild"
on your local machine, then each file path should start with "desiredBuild".

关于python - 将目录上传到 pinata ipfs API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70490020/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com