msgraph-sdk-java icon indicating copy to clipboard operation
msgraph-sdk-java copied to clipboard

When downoading from sharepoint with buffer size always getting maximum 8K buffer and not as we asked

Open ihudedi opened this issue 1 year ago • 8 comments

Describe the bug

When downloading file from sharepoint using graph api and set the buffer size to be downloaded only 8K ( maximum) is fetched ) instread of the given buffer size. InputStream inputStream = graphServiceClient.drives().byDriveId(driveId).items().byDriveItemId(getDriveItemIdFromRootPath(filePath)).content().get(); byte[] buf = new byte[cloudPartSizeWhenDownloadingToLocal]; int bytesRead; while ((bytesRead = srcInputStream.read(buf)) != -1) { byresRead is always maximum 8K and not per demand }

Expected behavior

The bytess returned from this method should aline with the request.

How to reproduce

see above

SDK Version

6.25.1

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

ihudedi avatar Jan 08 '25 21:01 ihudedi

Hi @Ndiritu Any updates? Thanks, Itay

ihudedi avatar Jan 15 '25 11:01 ihudedi

Hi @ihudedi

To control the number of bytes returned you'd need to download the Drive Item first & pass a Range header to the download URL - docs. The .../content endpoint doesn't support partial downloads

Lmk if you face any more issues.

Ndiritu avatar Jan 15 '25 12:01 Ndiritu

Hi @Ndiritu I don't want partial download. SO what you tell me that by default you download only 8K each call? And how do I download range content via java? Thanks, Itay

ihudedi avatar Jan 15 '25 12:01 ihudedi

@ihudedi /content should return the entire item. Do you mean that the API is only returning 8Kb of a larger file? Are you able to validate this using Graph Explorer or a raw HTTP call without the SDK?

You can use the requestConfiguration object to pass custom headers e.g. Range for the partial download

Ndiritu avatar Jan 15 '25 12:01 Ndiritu

Hi @Ndiritu When using content we get InputStream object. Trying to read X bytes always return 8K bytes maximum. I will try the range header to see I I get only the range Thanks, Itay

ihudedi avatar Jan 15 '25 14:01 ihudedi

Hi @Ndiritu Issue was resolved. Thanks, Itay

ihudedi avatar Jan 21 '25 08:01 ihudedi

Great to hear @ihudedi Are you able to share what the root cause was for future reference by others?

Ndiritu avatar Jan 23 '25 08:01 Ndiritu

Hi @Ndiritu The inputStream.read(buf)) always bring only max 8K bytes I used in parallel and fetch the stream in ranges. Still the read should fetch all the bytes in the buffer not only 8K Thanks, Itay

ihudedi avatar Jan 23 '25 10:01 ihudedi