0

I am pretty much new in Mongodb now what I want to do is to insert a pdf file of 3MB using JAVA driver and want change the chunk size from 256 to 1mb and then want to retrieve the second chunk say 2nd page of the pdf document. How can I do so. Thankyou.

1 Answers1

1

Generally, once a document has been written into GridFS you will need to re-write it (delete and save again) to modify the chunk size.

Since GridFS does not know anything about the format of the data in the file it can not help you get to the "2nd page". The InputStream implementation that is returned from GridFSDBFile does avoid reading blocks when you use the skip(long) method. If you know that the "2nd page" is N bytes into the file then you can skip that many bytes in the stream and start reading.

HTH, Rob

P.S. Remember that skip(long) returns the number of bytes actually skipped. You should not assume that skip(12) always skips 12 bytes.

P.P.S Starting to read from the middle of a PDF and making sense of what is there is going to be hard unless you have preserved state from the previous page(s).

Rob Moore
  • 3,343
  • 17
  • 18
  • Thanks about the **Skip()** function but how we can change chunk size say I have changed the size of the chunk before saving by **gfsinputfile.setChunkSize(values in bytes)** but I have noticed in output chunk size it always show **262144** how can I deal with it. –  Feb 21 '14 at 06:45
  • Have you tried using the save(long) variant instead of setting the chunk size and then calling save()? If you are using the GridFSInputFile.getOutpuStream() then you need to make sure setChunkSize(...) is call before getOutputStream(). Otherwise setChunkSize(...) is a no-op. – Rob Moore Feb 22 '14 at 19:47