Public
Script
February 9, 2024
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
const JWT = Deno.env.get("PINATA_JWT");
export default async function uploadByURL(url){
try {
const urlStream = await fetch(url)
const arrayBuffer = await urlStream.arrayBuffer()
const blob = new Blob([arrayBuffer])
const data = new FormData()
data.append("file", blob)
const upload = await fetch('https://api.pinata.cloud/pinning/pinFileToIPFS', {
method: 'POST',
headers: {
'Authorization': `Bearer ${JWT}`
},
body: data
})
const uploadRes = await upload.json()
console.log(uploadRes)
} catch (error){
console.log(error)
}
}
uploadByURL("https://imagedelivery.net/BXluQx4ige9GuW0Ia56BHw/a7c16ab0-31fd-406a-87f3-0da1b41a4000/original")
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
February 9, 2024