As I understand it, smart contracts are currently immortal by default. Does this mean that I could create a contract that happened to contain an encoded form of baby photos and have it stored forever? If not, what prevents it?
Nothing prevents it. 5 months ago, I demonstrated storing audio (a very highly compressed mp3 file) in the blockchain. And it's still there and being replicated by every full node today! Only 3.5kB and I had to pay quite a bit of ether, but still cool!
Check out Freakiest thing ever - the blockchain now has a voice! thread at Reddit.
To make this answer last the test of time (if something happens to the above link), here is the relevant command to run in your terminal:
geth --exec "eth.getTransaction('0xbb8ee9866ee67277986b6f40775469c7a674810ce99dce3caff0d1117c8dcdac').input" console | xxd -p -r | mpg321 -
A smarter way uses the storage only as a hash as other answers have said, use StorJ, IPFS, etc., because then you can store more off the blockchain and link to it.
The primary things "stopping you" would be:
- Block gas limits which are currently "voted on" by miners
- Amount of gas you would need to pay to store your data
Things like baby photos are going to be, at minimum, 600kB uncompressed. I am not incredibly familiar with image compression, so we will just work with the 600kB figure for the sake of example.
A transaction sending 46kB of compressed text consumed 1,720,210 gas and cost 0.0860105 Ether ($0.074 USD) at the end of October 2015. The price since then for Ether will continue to rise/fall, but ignoring that for a moment, let's do the math:
Storing the 600 kB image would cost 13 times more gas to store, so 22,362,821 gas would be consumed for a cost of $0.96 (if priced from Oct. 2015). The current block gas limit is 3,141,592 gas which is much less than the required amount to process the image in 1 transaction.
So it is possible to store images on the Ethereum blockchain, but a much cheaper solution would be to store a reference to that image (like a URL) to permanently store where the image is kept, granted that is not as useful as permanent storage. In the future, IPFS will likely be able to store data indefinately once they nail down an incentive system for people to store the data. Then it is just a matter of storing the IPFS hash that points to the image.
The data types that can be stored are limited, so storing baby photos would take a lot of code to map it to the available types. Plus of course you need to pay Ether to the contract to use its storage, so it's not free.
Other option to store data is: