Share a Private File
In this guide, you will use Lightstreams node to share a file in a peer-to-peer manner with another node. No intermediary server will be used.
Create a test file
echo "SmartVault is awesome." > smart_vault.txtAdd the file to your node
curl -X POST \
http://localhost:9091/storage/add \
-H 'multipart/form-data; boundary="===============1648430772=="' \
-F owner=YOUR_ACCT \
-F password=YOUR_PWD \
-F file=@smart_vault.txtWhere:
filethe absolute path to the file you want to shareownerthe address of the file owner. This address needs to have a positive PHT balance to pay for the smart contract transaction feespasswordthe password to unlock owner account
Output:
{
"meta":"QmbVtvd1rD9pDHpx7AUqrsh3CoCMW3Na3g4fAwXJxyaawz",
"acl":"0x7000f85C4065643435E8A350655F3153c7dd030E"
}Note:
"meta"a public file describing the file meta information. The protected content is stored in a secure manner. You can share this address with everyone. They won't be able to access the protected content. Only read the file metadata."acl"a smart contract address for controlling all the file access permissions and rules for the .
Grant permission to another device
Create a new account for node 2:
Generate the token for node 2 account 0xFb0bC1AC4a627fcdd215b7eF9617172276a402d0:
Attempt to read the protected file with node 2 account credentials (token): Note: Replace [meta] and [token] in the query string with the meta hash and token string you generated.
Where:
metais the protected's file public meta address:QmbVtvd1rD9pDHpx7AUqrsh3CoCMW3Na3g4fAwXJxyaawztokenis your auth token generated by/user/signinrequest
Output:
This error is expected because the file owner never actually granted permission to Lightstreams node 2 account: 0xFb0bC1AC4a627fcdd215b7eF9617172276a402d0.
Let's grant Leth node 2 a read permission.
Granting a READ permission
From Node 1 account run:
Where:
aclcorresponds to the smart contract address provided after we published the filetois the account we are granting access topermissionis the permission to grant, it may be:['read', 'write', 'admin', 'noaccess']
Try to access the file again
Reading the meta file
In case you want to get information about the privately stored file, you can do so using the /storage/meta route.
This returns public information about the file, without revealing its content.
Output:
Note:
filenameis the original filename when file was uploadedextis the original file extensionownerwho uploaded the filehashthe hash of the protected file stored in IPFS (not the public Meta file hash)acladdress of the contract handling file permissions
Congratulations! You just shared a private file over the internet in a peer-to-peer manner.
Last updated
Was this helpful?