stijnsanders / TMongoWire

Delphi MongoDB driver
MIT License
102 stars 37 forks source link

File corrupted when using TMongoStream #22

Closed waltrick closed 9 years ago

waltrick commented 9 years ago

Hi Sanders,

I have the following situation: Upload files in php and downlod in your component, when I do that the file is corrupted. But when I upload and downlod for its component works correctly.

Any suggestions?

stijnsanders commented 9 years ago

Could you post a small (~100 bytes) file with PHP, then use the mongo shell to do find({}) on the "x.files" and "x.chunks" collections to get the JSON? and post it here, then I can compare what PHP does and what TMongoStream does and where's the difference. (what mongo,delphi version are you using?)

waltrick commented 9 years ago

Sanders,

One difference I found was that the key value "Length" of ".files" to be charged by the procedure TBSONDocument.Load (bsonDoc.pas), is higher in the files generated by PHP because when generated by the component, this value remains the same. ~line 434, stmRead (@ i, 4);

I created an environment for testing:

Mongo's Server Version: 2.6.0 Host: 179.188.20.128 Port: 27017 Obs: No Auth.

PHP Upload Version: 5.5 Link: http://app.spezzi.com.br/documentos

Delphi Downlod Version: XE2 TMongoWire\demo\example2 (your example)

FilesCollection='spezzi.mongo_documentos';

Sorry my english a child of 7 years (google translate) .

waltrick commented 9 years ago

News, I created a java applet, and the files were created properly.

stijnsanders commented 9 years ago

I can't access the URL you supply above. I'm not sure what you mean by the 'length' field, but I'm glad the java applet works. Perhaps it's PHP that is misbehaving? I'll close this issue, but feel free to open a new issue if you encounter this problem again. If you do, please post relevant pieces of JSON so I can compare and find what's wrong.

waltrick commented 9 years ago

Sanders,

I do not know if the problem was in php or MongoWire, but worked as a java application, actually the problem is in your component. In short, generated files are corrupted when downloading PHP in Delphi (MongoWire).

Below is the JSON:

{    "_id": ObjectId ("5446c26969f3cb8b6bd3ebba")    "filename": "spezzi.jpg"    "filetype", "image \ / jpeg"    "uploadDate": ISODate ("2014-10-21T20: 30: 33.359Z")    "length": NumberInt (60466)    "chunksize": NumberInt (261120)    "md5", "79d13d30c16f476676a512538ad2c6bc" }

The .files and .chunks are exactly alike when generated in PHP and Delphi, made ​​this comparison.

stijnsanders commented 9 years ago

It is correct the chunksize is different? https://github.com/stijnsanders/TMongoWire/blob/master/mongoStream.pas#L59 $40000=262144 <> 261120

waltrick commented 9 years ago

Sanders, I made this change to stay compatible.

"Changed in version 2.4.10: The default chunk size changed from 256k to 255k." http://docs.mongodb.org/manual/core/gridfs/#chunk-disambiguation

//mongoStreamDefaultChunkSize=$40000;//256KB mongoStreamDefaultChunkSize=$3FC00; //255kb

stijnsanders commented 9 years ago

Thank you. I've updated it.