Steemit Images under 1mb could be stored on the Blockchain using Base64!

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@blueorgy·
0.000 HBD
Steemit Images under 1mb could be stored on the Blockchain using Base64!
One of the biggest issues with Steemit is that it has to rely on outside resources to host images that are held within its posts. Why this is a problem is because its **not decentralized**, and that's what were all about here. 

We essentially rely on these outside sources for a majority of the content on steemit (that being images). I personal run one of these resources http://steemimg.com and after getting into quite a long debate / discussion on the reliability of individuals and how if these resources **"pulled the plug"** we would be fuc*ed! I put everything down and started to look into how we could get these images on the Blockchain.

<b>What I came to is Base64. But is this the answer? When should we use it and when we shouldn't we?</b>

OK, for those who don't know what Base64 image encoding is...
> The particular set of 64 characters chosen to represent the 64 place-values for the base varies between implementations. The general strategy is to choose 64 characters that are both members of a subset common to most encodings, and also printable. 

Essentially is a really long string of characters that all modern browsers can decode and rearrange back into the image that you originally encoded.

<b>Here an example</b>
https://www.steemimg.com/images/2016/07/27/steemitfirstb24d9.jpg

(which is the image I created in hopes that I would have actually been able to accomplish this task without the help of the steemit developers)

Looks like this in Base64
> data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4QCqRXhpZgA ATU0AKgAAAAgABgESAAMAAAABAAEAAAEaAAUAAAABAAAAVgEbAAUAAAAB
AAAAXgEoAAMAAAABAAIAAAExAAIAAAARAAAAZodpAAQAAAABAAAAeAAAAA
AAAABIAAAAAQAAAEgAAAABQWRvYmUgSW1hZ2VSZWFkeQAAAA... 

Ok for those who know how long these can get that's about 4% of the total length .. YIKES!

So one of the biggest draw backs to this is the pure size of the Base64 string. It's huge! So would this be practical to be put onto the blockchain? 

On further testing It can be placed inside the Json_metadata inside the block, using #Piston (Thanks @xeroc) I wrote little python script to place the actual Base64 string into the meta and it was successful. *I will also post a comment right after I finish this post and do the same so everyone can take a look.* It also posted, time wise, without any issues and when looking at the post via steemd, again no problems!

Now although I don't believe their to be any size limitations to Base64 other then: (source caniuse.com)
> Although Mozilla supports data URIs of essentially unlimited length, browsers are not required to support any particular maximum length of data. For example, the Opera 11 browser limits data URIs to around 65000 characters.
Support in Internet Explorer 8 is limited to images and linked resources like CSS files, not HTML files. Max URI length in IE8 is 32KB. In IE9 JavaScript files are supported too and the maximum size limit set to 4GB.

I think it might be safe to say the Blockchain could handle images 1mb and under and I think that would handle a majority of images needed for posts and comments. And Yes, Gif's can be Base64, however a lot of these types of images are larger then 1mb so that may be a problem and the length of the string again would be even larger.

On a coding perspective it would be quite simple: Add to Steem within Posting Function around the image handler. (Possibly right before the https://img1.steemit.com/0x0 is added)
1. <code> import Base64</code> 
2. <code> While foudnImgSrc.Size <= 1000kb { encoded = base64.b64encode('foudnImgSrc')</code> 
<code>newImgURL = base64.b64decode(encoded) }</code> 
3. <code> json_metadata	"{"tags": ["steemit"], "image1..2..3": ["data:image/data:image/jpeg;bas... </code>
4. <code> img src = image1 </code> 

Number 4 using the metadata tag to replace the image url on the page will save a on load times and the size of the blockchain. Also the max body length limit would be broken and the post would return **comment pruned due to size**

When it comes to displaying them its pretty straight forward however img1 steemit would have to be modified to handle the Base64 as well as normal images.

So there you have it, we could have images stored on the blockchain using Base64!
I'm going to call it a night for now but I'm going to continue my work on finding out our best solution for images on steemit.

Blue
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,