github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/pinning/pin_file_locally.go (about) 1 package pinning 2 3 import ( 4 "os" 5 6 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" 7 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config" 8 shell "github.com/ipfs/go-ipfs-api" 9 ) 10 11 // pinFileLocally pins the file locally to the local IPFS node 12 func (s *Service) pinFileLocally(chain, filepath string) (base.IpfsHash, error) { 13 file, err := os.OpenFile(filepath, os.O_RDONLY, 0) 14 if err != nil { 15 return "", err 16 } 17 defer file.Close() 18 19 sh := shell.NewShell(config.GetPinning().LocalPinUrl) 20 cid, err := sh.Add(file, shell.Pin(true)) 21 if err != nil { 22 return "", err 23 } 24 return base.IpfsHash(cid), nil 25 }