A few weeks ago, the question came up: > Is it possible to get files into the STEEM blockchain? As I have discovered, with a few little tricks you can get everything into the STEEM blockchain. *The following scripts are for testing purposes and not for productive use* *I wrote this tutorial for @pcsg-dev, but I don't want to post it with this account for a variety of reasons. I also posted an issue for Steemit and waited some time until it could be reacted to, but it is not taken seriously.*  ### What is needed - A STEEM account - One file - Some know-how in programming - Our example scripts are written in PHP I tried to make the tutorial as simple as possible. However, some prerequisites are necessary, so I classify this for experienced users. ### What will you learn: - How to split files with PHP - How can you upload files to the STEEM blockchain - How can you reassemble split files with PHP ### Difficulty - Intermediate General procedure ------ - We split our file into small pieces - This is because STEEM has a maximum length of a post - We convert each section into text - This is because we get binary data only badly in a post - We write a post / comment for each section - The content of a post is the content of a file - We read every single post and put all content back together again Tutorial ------ - All examples are written in PHP, but the procedure can be implemented in any language imaginable. - Let us take Steemit's white paper as an example. ### Split the file Splitting the file is easy on the right. **Procedure** - We're looking at the size of the file, - split the file into many small sections with `fread($file_handle, $buffer)`, - done **Partial section Example** ```php // ... // how many parts would be existed $parts = $file_size / $buffer; // ... for ($i = 0; $i < $parts; $i++) { // read buffer sized amount of the file $file_part = fread($file_handle, $buffer); // the filename of the part $file_part_path = $store_path.$file_name.".part$i"; // create and write the part $file_new = fopen($file_part_path, 'w+'); fwrite($file_new, $file_part); fclose($file_new); } // ... ``` You can find the complete example in [split.php](https://github.com/pcsg/steem-tutorials/blob/master/upload-a-file/split.php) ### Upload the file Here's the interesting part. If we now have our small pieces, we have to convert every single piece into text that we can upload as mail. **Procedure** - We'll take a section, - read the contents of the file with `file_get_contents()`, - convert the binary content to text. For example with `bin2hex()`, - write a new post with this content **Example** ```php // ... $fileData = bin2hex(file_get_contents('PATH_TO_FILE/steem-whitepaper.pdf.part0')); // ... ``` You can find the complete example in [upload.php](https://github.com/pcsg/steem-tutorials/blob/master/upload-a-file/upload.php) ### Download the file For the whole thing to make sense, we have to get the file out of the blockchain. With the LightRPC Client (https://github.com/hernandev/light-rpc) it is an easy to read single posts via PHP. If you don't know how to install it, just have a look at https://github.com/hernandev/light-rpc There is a wonderful explanation. *If requested, I can also write a small tutorial for you here.* **Procedure** - We're reading our summary file, - get the contents of every post, - convert this content back to binary data, - pack all contents into one file. *In our example file we have moved the download part into a function, so that the whole thing is a bit clearer.* ```php /** * This function fetch a steemit post * * @param string $username * @param string $permlink * @return mixed */ function getContent($username, $permlink) { $Client = new Client('https://api.steemit.com'); $Request = new Request('content_api', 'get_content', [$username, $permlink]); $Response = $Client->send($Request); if ($Response->isError()) { var_dump($Response->error()); exit; } $response = $Response->toArray(); $result = $response['result']; return $result['body']; } ``` Now, to the "how we get it all together" part. In our `$summary` we have all our files, we go through them one by one and put our whitepaper back into one file. ```php // now we go through all the files and get the content from the steem blockchain foreach ($summary as $part => $permlink) { echo $part.PHP_EOL; // get the content from the steem blockchain with our helper function $content = getContent('pscg.test', $permlink); // the content is in hex text, but we need binary. // if you still remember we converted it for the steem blockchain // now we convert it back to binary data $content = hex2bin($content); // this binary data is now attached to our file file_put_contents($filename, $content, \FILE_APPEND); } ``` You can find the complete example in [download.php](https://github.com/pcsg/steem-tutorials/blob/master/upload-a-file/download.php) I hope the tutorial was fun and taught you a little bit. I wish you a lot of fun Hen
author | dehenne |
---|---|
permlink | loading-a-file-into-the-steem-blockchain |
category | utopian-io |
json_metadata | {"tags":["utopian-io","tutorials","steem"],"users":["pcsg-dev"],"image":["https://cdn.steemitimages.com/DQmUmN4t6FbSNrQ7B2NxjvScgigK3nP9Komvx4Hsu7iCNfa/bandbreite-computer-daten-1148820.jpg"],"links":["https://github.com/pcsg/steem-tutorials/blob/master/upload-a-file/split.php","https://github.com/pcsg/steem-tutorials/blob/master/upload-a-file/upload.php","https://github.com/hernandev/light-rpc","https://github.com/pcsg/steem-tutorials/blob/master/upload-a-file/download.php"],"app":"steemit/0.1","format":"markdown"} |
created | 2018-07-11 04:37:57 |
last_update | 2018-07-11 05:03:21 |
depth | 0 |
children | 6 |
last_payout | 2018-07-18 04:37:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 34.872 HBD |
curator_payout_value | 11.085 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 5,362 |
author_reputation | 8,032,043,781,732 |
root_title | "Loading a file into the STEEM blockchain" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 64,240,370 |
net_rshares | 22,406,930,778,989 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
yuxi | 0 | 2,980,974,359 | 10% | ||
alexvan | 0 | 10,539,685,237 | 20% | ||
justatouchfey | 0 | 4,940,615,869 | 100% | ||
detlev | 0 | 1,742,596,203 | 2% | ||
oendertuerk | 0 | 35,006,992,198 | 20% | ||
macchiata | 0 | 7,197,730,453 | 100% | ||
peat | 0 | 265,436,021 | 100% | ||
techtek | 0 | 50,082,469,802 | 100% | ||
jjb777 | 0 | 8,914,546,981 | 100% | ||
scorer | 0 | 39,770,197,743 | 100% | ||
mcfarhat | 0 | 10,576,264,624 | 15% | ||
gregan | 0 | 7,926,321,295 | 100% | ||
utopian-io | 0 | 22,146,423,687,642 | 14.38% | ||
oger | 0 | 1,970,391,578 | 100% | ||
papke | 0 | 271,785,760 | 100% | ||
steemitstats | 0 | 3,288,748,115 | 5% | ||
ravenruis | 0 | 8,766,462,491 | 50% | ||
maxpatternman | 0 | 31,099,508,470 | 100% | ||
liberviarum | 0 | 7,694,400,342 | 50% | ||
smotradoc | 0 | 569,538,957 | 100% | ||
garikpetrosyan | 0 | 569,072,284 | 100% | ||
sonagalstyan | 0 | 569,723,072 | 100% | ||
wolfguards | 0 | 10,450,257,727 | 100% | ||
marksbanana | 0 | 569,725,981 | 100% | ||
gracefulestrogen | 0 | 569,725,981 | 100% | ||
floorsopera | 0 | 569,725,981 | 100% | ||
randallvillan | 0 | 569,729,216 | 100% | ||
klimekaczma | 0 | 569,725,981 | 100% | ||
palmcomposed | 0 | 569,501,215 | 100% | ||
eczemamuon | 0 | 569,725,981 | 100% | ||
rattyopera | 0 | 569,723,072 | 100% | ||
chewycareless | 0 | 569,725,981 | 100% | ||
borndead10 | 0 | 569,732,157 | 100% | ||
lizakotova | 0 | 569,729,216 | 100% | ||
hsufrank | 0 | 569,725,981 | 100% | ||
marina.astakova | 0 | 569,725,981 | 100% | ||
antalovaelena | 0 | 569,725,981 | 100% | ||
reginasamkova | 0 | 569,723,072 | 100% | ||
pollfullscreen | 0 | 569,723,072 | 100% | ||
towheelocate | 0 | 569,723,072 | 100% | ||
curiouscred | 0 | 569,723,072 | 100% | ||
aleindium | 0 | 569,723,072 | 100% | ||
cootroach | 0 | 569,723,072 | 100% | ||
trademarkroofer | 0 | 569,723,072 | 100% | ||
sleepyneodymium | 0 | 569,723,072 | 100% | ||
filletsslither | 0 | 569,723,072 | 100% | ||
batchjocular | 0 | 569,723,072 | 100% | ||
shamefulhasty | 0 | 569,723,072 | 100% | ||
fuzzythumb | 0 | 425,232,496 | 100% | ||
marcfrelon2 | 0 | -94,508,772 | -100% | ||
dertluc | 0 | 0 | -100% | ||
jilophu | 0 | -100,509,557 | -100% | ||
steempolki | 0 | -57,850,238 | -100% | ||
balticbadger | 0 | 529,716,585 | 100% | ||
seldonsplan | 0 | 535,794,002 | 100% | ||
icebergbitos | 0 | -79,137,026 | -100% | ||
petitzob | 0 | -88,268,221 | -100% | ||
fertuis | 0 | 0 | -100% |
Really cool! I will give this a try
author | balticbadger |
---|---|
permlink | re-dehenne-loading-a-file-into-the-steem-blockchain-20180711t051533017z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-07-11 05:15:33 |
last_update | 2018-07-11 05:15:33 |
depth | 1 |
children | 0 |
last_payout | 2018-07-18 05:15:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 35 |
author_reputation | 68,520,530,759,841 |
root_title | "Loading a file into the STEEM blockchain" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 64,243,392 |
net_rshares | 0 |
Hey @dehenne, That is such a cool idea, and nice approach to implementing it! As @portugalcoin mentioned, following the template is normally preferred, yet your post does bring additional value of course to our tutorials. It would have been interesting to see this as a live example with actual screenshots and outcome. If you did not want to try this out on live, maybe you can check on a Steem testnet https://developers.steem.io/testnet/ ? I haven't tried it myself but could be worthy in exploratory situations. Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category. To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/8/21233122). ---- Need help? Write a ticket on https://support.utopian.io/. Chat with us on [Discord](https://discord.gg/uTyJkNm). [[utopian-moderator]](https://join.utopian.io/)
author | mcfarhat |
---|---|
permlink | re-dehenne-loading-a-file-into-the-steem-blockchain-20180712t082525252z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"users":["dehenne","portugalcoin"],"links":["https://developers.steem.io/testnet/","https://join.utopian.io/guidelines","https://review.utopian.io/result/8/21233122","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"} |
created | 2018-07-12 08:25:51 |
last_update | 2018-07-12 08:25:51 |
depth | 1 |
children | 1 |
last_payout | 2018-07-19 08:25:51 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,008 |
author_reputation | 150,651,671,367,256 |
root_title | "Loading a file into the STEEM blockchain" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 64,383,001 |
net_rshares | 8,258,387,566 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
dehenne | 0 | 3,003,834,014 | 100% | ||
espoem | 0 | 5,254,553,552 | 5% |
Thank you for the approving. In real live example is to be enjoyed with caution. After my vacation I can think about setting something up for the Testnet. ;-)
author | dehenne |
---|---|
permlink | re-mcfarhat-re-dehenne-loading-a-file-into-the-steem-blockchain-20180712t091914944z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-07-12 09:19:15 |
last_update | 2018-07-12 09:19:15 |
depth | 2 |
children | 0 |
last_payout | 2018-07-19 09:19:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 158 |
author_reputation | 8,032,043,781,732 |
root_title | "Loading a file into the STEEM blockchain" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 64,387,292 |
net_rshares | 0 |
Thank you for your contribution. - Doesn't follow the template for the tutorials <a href="https://github.com/utopian-io/editor-templates/blob/master/tutorials">link</a> : You don't have the <b>repository</b> and <b>Proof of Work Done</b>. ---- Need help? Write a ticket on https://support.utopian.io/. Chat with us on [Discord](https://discord.gg/uTyJkNm). [[utopian-moderator]](https://join.utopian.io/)
author | portugalcoin |
---|---|
permlink | re-dehenne-loading-a-file-into-the-steem-blockchain-20180711t204411066z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"links":["https://github.com/utopian-io/editor-templates/blob/master/tutorials","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"} |
created | 2018-07-11 20:44:09 |
last_update | 2018-07-12 21:35:27 |
depth | 1 |
children | 0 |
last_payout | 2018-07-18 20:44:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 410 |
author_reputation | 598,828,312,571,988 |
root_title | "Loading a file into the STEEM blockchain" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 64,330,964 |
net_rshares | 5,254,553,552 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
espoem | 0 | 5,254,553,552 | 5% |
Congratulations @dehenne! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) : [](http://steemitboard.com/@dehenne) Award for the number of upvotes <sub>_Click on the badge to view your Board of Honor._</sub> <sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub> > Support [SteemitBoard's project](https://steemit.com/@steemitboard)! **[Vote for its witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1)** and **get one more award**!
author | steemitboard |
---|---|
permlink | steemitboard-notify-dehenne-20180917t060801000z |
category | utopian-io |
json_metadata | {"image":["https://steemitboard.com/img/notify.png"]} |
created | 2018-09-17 06:08:00 |
last_update | 2018-09-17 06:08:00 |
depth | 1 |
children | 0 |
last_payout | 2018-09-24 06:08:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 672 |
author_reputation | 38,975,615,169,260 |
root_title | "Loading a file into the STEEM blockchain" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 71,510,623 |
net_rshares | 0 |
Hey @dehenne **Thanks for contributing on Utopian**. Weβre already looking forward to your next contribution! **Want to chat? Join us on Discord https://discord.gg/h52nFrV.** <a href='https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
author | utopian-io |
---|---|
permlink | re-loading-a-file-into-the-steem-blockchain-20180712t083508z |
category | utopian-io |
json_metadata | "{"app": "beem/0.19.42"}" |
created | 2018-07-12 08:35:09 |
last_update | 2018-07-12 08:35:09 |
depth | 1 |
children | 0 |
last_payout | 2018-07-19 08:35:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 299 |
author_reputation | 152,955,367,999,756 |
root_title | "Loading a file into the STEEM blockchain" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 64,383,671 |
net_rshares | 5,637,602,769 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
espoem | 0 | 5,637,602,769 | 5% |