Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For storing binary data like images you can use <a href="http://www.mongodb.org/display/DOCS/GridFS+Specification" rel="noreferrer">GridFS</a> or implement your own realization; Download the <a href="https://github.com/mongodb/mongo-java-driver" rel="noreferrer">driver</a> and look at <code>src/test/com/mongodb/gridfs/GridFSTest.java</code> ;)</p> <p>Edit: you are lucky today! I made complete code for you;) Enjoy!</p> <pre class="lang-java prettyprint-override"><code>package mongodb.testing.java; import com.mongodb.*; import com.mongodb.gridfs.*; import java.io.*; public class Main { public static byte[] LoadImage(String filePath) throws Exception { File file = new File(filePath); int size = (int)file.length(); byte[] buffer = new byte[size]; FileInputStream in = new FileInputStream(file); in.read(buffer); in.close(); return buffer; } public static void main(String[] args) throws Exception { //Load our image byte[] imageBytes = LoadImage("C:/Temp/bear.bmp"); //Connect to database Mongo mongo = new Mongo( "127.0.0.1" ); String dbName = "GridFSTestJava"; DB db = mongo.getDB( dbName ); //Create GridFS object GridFS fs = new GridFS( db ); //Save image into database GridFSInputFile in = fs.createFile( imageBytes ); in.save(); //Find saved image GridFSDBFile out = fs.findOne( new BasicDBObject( "_id" , in.getId() ) ); //Save loaded image from database into new image file FileOutputStream outputImage = new FileOutputStream("C:/Temp/bearCopy.bmp"); out.writeTo( outputImage ); outputImage.close(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload