-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIPFS.py
48 lines (40 loc) · 1004 Bytes
/
IPFS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from moralis import evm_api
import base64
import os
from dotenv import load_dotenv
load_dotenv()
#image upload
def uploadToIPFS(path:str):
api_key = os.getenv('API_KEY')
with open(path, "rb") as img_file:
BASE64IMG = (base64.b64encode(img_file.read())).decode("ascii")
imageBody = [
{
"path": "RSA.png",
"content": BASE64IMG,
}
]
imagePath = evm_api.ipfs.upload_folder(
api_key=api_key,
body=imageBody,
)
#metadata upload
import json
content = {
"name": "Test",
"description": "Modified RSA Test Image",
"image":imagePath[0]['path'],
}
metadataBody = [
{
"path": "metadata.json",
"content": base64.b64encode(bytes(json.dumps(content), "ascii")).decode(
"ascii"
),
}
]
result = evm_api.ipfs.upload_folder(
api_key=api_key,
body=metadataBody,
)
return result[0]['path']