[JAVA-3280] gridfs can not upload empty file Created: 30/Apr/19  Updated: 27/Oct/23  Resolved: 26/Aug/19

Status: Closed
Project: Java Driver
Component/s: GridFS
Affects Version/s: 3.10.1
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Li Tc Assignee: John Stewart (Inactive)
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

if the file size is 0,the GridFSUploadStreamImpl line 96 while pass and keep the var “len” is 0 and GridFSBucketImpl line 201 need "len" val is -1 to stop the loop, so the loop will never end.

i think need throw exception or just upload a empty file



 Comments   
Comment by John Stewart (Inactive) [ 02/Aug/19 ]

I tried to reproduce this issue with the following code:

        GridFSUploadStream uploadStream = gridFSBucket.openUploadStream("sampleData");
        byte[] data = Files.readAllBytes(new File("/tmp/0.txt").toPath());
        uploadStream.write(data);
        uploadStream.close();
        System.out.println("The fileId of the uploaded file is: " + uploadStream.getObjectId().toHexString());

This code succeeds. Could you provide code that reproduces the issue? Thanks.

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