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.
I tried to make the tutorial as simple as possible.
However, some prerequisites are necessary, so I classify this for experienced users.
Splitting the file is easy on the right.
Procedure
fread($file_handle, $buffer),Partial section Example
// ...
// 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
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
file_get_contents(),bin2hex(),Example
// ...
$fileData = bin2hex(file_get_contents('PATH_TO_FILE/steem-whitepaper.pdf.part0'));
// ...
You can find the complete example in upload.php
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
In our example file we have moved the download part into a function, so that the whole thing is a bit clearer.
/**
* 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.
// 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
I hope the tutorial was fun and taught you a little bit.
I wish you a lot of fun
Hen