Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-367

java bson exception while reading files from gridfs (that was storead by php driver)

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.6.2
    • Affects Version/s: 2.6.1
    • Component/s: API
    • Labels:
    • Environment:
      windows, db: mongodb-win32-i386-1.8.1, php driver: mongo-1.1.4-WINDOWS, java: mongo-2.6.1.jar
    • Major Change

      Hi.
      My system is writen on php and java.
      I started testing php and java drivers to communicate with GridFs.
      I can store and get files with php, and so with java, but
      when I store a file with php in GridFs and then want to get and write it to fs with java it fails:

      java.lang.ClassCastException: org.bson.types.Binary cannot be cast to [B
      at com.mongodb.gridfs.GridFSDBFile.getChunk(GridFSDBFile.java:89)
      at com.mongodb.gridfs.GridFSDBFile.writeTo(GridFSDBFile.java:75)

      but when with java and then with php, everything ok.

      sample code i am using:

      PHP WRITE CODE

      $m = new Mongo();
      $fs = $m->test->getGridFs();
      echo $fs->storeFile("J:
      1.avi", array('filename' => 'filename1'), array('safe' => true));

      JAVA READ CODE

      GridFS myFS;
      try {
      myFS = new GridFS(new Mongo().getDB("test"));
      GridFSDBFile f = myFS.findOne("filename1");
      if(f!=null)

      { f.writeTo("J:\\res.txt"); System.out.println("true"); }

      else

      { System.out.println("false"); }


      } catch (Exception ex)

      { Logger.getLogger(Ufs.class.getName()).log(Level.SEVERE, null, ex); }

      ps

      I danced a lot with this code, modified parameters, changed ids, php and java drivers on older versions. Nothing helped.
      And java gets file by id fine, but when saving getting exception.

      What I am doing wrong ?

      Thanks.

            Assignee:
            Unassigned Unassigned
            Reporter:
            alezozov alezozov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: