[JAVA-367] java bson exception while reading files from gridfs (that was storead by php driver) Created: 02/Jun/11  Updated: 11/Sep/19  Resolved: 02/Jun/11

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 2.6.1
Fix Version/s: 2.6.2

Type: Task Priority: Critical - P2
Reporter: alezozov Assignee: Unassigned
Resolution: Done Votes: 0
Labels: bson, crash
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

windows, db: mongodb-win32-i386-1.8.1, php driver: mongo-1.1.4-WINDOWS, java: mongo-2.6.1.jar


Issue Links:
Depends
depends on JAVA-368 When reading back binary of type B_GE... Closed
Backwards Compatibility: Major Change

 Description   

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.



 Comments   
Comment by Antoine Girbal [ 02/Jun/11 ]

This is due to bug JAVA-368.
Fix will be available with 2.6.2 to be released probably today.
If you use an older driver (e.g. 2.5.3) it should work fine.

Generated at Thu Feb 08 08:52:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.