首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将目录上载到pinata ipfs

将目录上载到pinata ipfs
EN

Stack Overflow用户
提问于 2021-12-26 21:34:48
回答 1查看 937关注 0票数 2

我试图将pngs目录上传到pinata,但我一直收到以下错误:

代码语言:javascript
复制
{'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!'}

下面是我尝试过的代码:

代码语言:javascript
复制
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)目录,然后在那里有一堆数字图片。如果有其他方法可以做到的话,伊马克!谢谢!

EN

回答 1

Stack Overflow用户

发布于 2022-06-30 18:37:45

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

代码语言:javascript
复制
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".
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70490020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档