我正在尝试将 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
tea[email protected] /cdn-cgi/l/email-protection. 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".
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)