R : readBin and writeBin ( for storing/retrieving MySQL BLOBs or LONGBLOBs )

Viewed 4571

I'm using the readBin function to save a file as MySQL BLOB as described in this article ( http://www.r-bloggers.com/save-r-plot-as-a-blob/ )

plot_binary <- paste(readBin("temp.png", what="raw", n=1e6), collapse="")

My question is : Once this is in the database how do I dump it back into a file ?

> f = file ( "backIntoFile.png", "wb")
> writeBin(object = plot_binary, con = f ) 
> close(f)

This does not work ; the file does not seem to be a valid png ;

CHeers!

4 Answers
Related