【IPFS相關】使用rails和rest-client通過API遠端新增
我有一個執行的遠端IPFS節點受HTTP基本身份驗證保護,這裡是我的設定教程:tps://medium.com/@cvcassano/protecting-an-ipfs-node-with-nginx-reverse -proxy-上的ubuntu-18-04-e56685a10bcc
現在我需要從rails後端向IPFS新增一個檔案。幸運的是,IPFS HTTP API非常棒,我可以使用rest-clientgem將檔案新增到IPFS。
以下是我的表現。請注意,我正在使用HTTP基本身份驗證,這就是在請求中設定user和password鍵的原因。如果您的IPFS API未受HTTP基本身份驗證保護,則可以省略這些。
響應= RESTClient實現:: Request.execute(
方法:柱,
網址: ' https://ipfs.deco.network/api/v0/add' ,
使用者: 'ipfsuser',
密碼:ENV [ 'DECONET_IPFS_API_PASSWORD'],
超時:600,#Optional
payload:{
multipart:true,
file:File.new("/path/to/image.jpg", 'rb') } ) parsed = JSON.parse(response.body) ipfs_hash = parsed ['Hash']
執行此程式碼後,該ipfs_hash變數將包含您上載的物件的ipfs雜湊值。
祝好運!
你可以訪問
連結:https://github.com/ipfs/ipfs/issues/374
【IPFS相關】由IPFS原力區譯製整理,收集外網中各領域人士在使用或開發IPFS及其相關應用時所分享的文章內容。
IPFS原力區官網:https://ipfsforce.com
IPFSER社群: https://ipfser.org
微博:https://weibo.com/ipfsforce