-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
34 lines (27 loc) · 970 Bytes
/
index.ts
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
import fs from 'fs';
import { FleekSdk, PersonalAccessTokenService } from '@fleekxyz/sdk';
import dotenv from 'dotenv';
dotenv.config();
const pat = process.env.PAT || '';
const project_id = process.env.PROJECT_ID || '';
const patService = new PersonalAccessTokenService({
personalAccessToken: pat,
projectId: project_id,
})
const fleekSdk = new FleekSdk({ accessTokenService: patService })
async function uploadFileToIPFS(filename: string, content: Buffer) {
const result = await fleekSdk.ipfs().add({
path: filename,
content: content
});
return result;
}
const fileContent = fs.readFileSync('fleek.jpg');
uploadFileToIPFS('fleek.jpg', fileContent).then( result => {
console.log('File uploaded to IPFS:', result);
console.log( 'IPFS URL:', `https://cf-ipfs.com/ipfs/${result.cid}`)
}).catch(error => {
console.error('Error uploading file to IPFS:', error);
}).finally(() => {
process.exit();
});