Lesson 11: create_metadata.py - No IPFS URL returned #188
Answered
by
PatrickAlphaC
toddabraham
asked this question in
Q&A
-
After running my create_metadata.py script, I'm not getting an IPFS URL returned, but there's no error.
from brownie import AdvancedCollectible, network
from scripts.helpful_scripts import get_breed
from metadata.sample_metadata import metadata_template
from pathlib import Path
import requests
def main():
advanced_collectible = AdvancedCollectible[-1]
number_of_advanced_collectibles = advanced_collectible.tokenCounter()
print(f"You have created {number_of_advanced_collectibles} collectibles!")
for token_id in range(number_of_advanced_collectibles):
breed = get_breed(advanced_collectible.tokenIdToBreed(token_id))
metadata_file_name = (
f"./metadata/{network.show_active()}/{token_id}-{breed}.json"
)
collectible_metadata = metadata_template
if Path(metadata_file_name).exists():
print(f"{metadata_file_name} already exists! Delete it to overwrite")
else:
print(f"Creating Metadata file: {metadata_file_name}")
collectible_metadata["name"] = breed
collectible_metadata["description"] = f"An adorable {breed} pup!"
print(collectible_metadata)
image_path = "./img/" + breed.lower().replace("_", "-") + ".png"
# image_uri = upload_to_ipfs(image_path)
# collectible_metadata["image"] = image_uri
def upload_to_ipfs(filepath):
with Path(filepath).open("rb") as fp:
image_binary = fp.read()
ipfs_url = "http://127.0.0.1:5001"
endpoint = "/api/v0/add"
response = requests.post(ipfs_url + endpoint, files={"file": image_binary})
ipfs_hash = response.json()["Hash"]
filename = filepath.split("/")[-1:][0]
image_uri = f"https://ipfs.io/ipfs/{ipfs_hash}?filename={filename}"
print(image_uri)
return image_uri |
Beta Was this translation helpful? Give feedback.
Answered by
PatrickAlphaC
Oct 12, 2021
Replies: 1 comment 1 reply
-
You're not running # image_uri = upload_to_ipfs(image_path) You need to run that to get an image URI |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
PatrickAlphaC
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're not running
upload_to_ipfs
, since you have it commented out:# image_uri = upload_to_ipfs(image_path)
You need to run that to get an image URI