我试图将pngs目录上传到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)目录,然后在那里有一堆数字图片。如果有其他方法可以做到的话,伊马克!谢谢!
发布于 2022-06-30 18:37:45
也许您在每个文件中添加了绝对路径,而不是相对文件路径?
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".https://stackoverflow.com/questions/70490020
复制相似问题