You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I couldn't manage to have the LargeFileUploadTask to work.
While debugging I noticed that LargeFileUploadTask.upload() does not add the Content-Length header to the request, as specified here
com.microsoft.kiota.ApiException: generalException
at com.microsoft.kiota.ApiExceptionBuilder.withMessage(ApiExceptionBuilder.java:45)
at com.microsoft.graph.core.requests.upload.UploadResponseHandler.handleResponse(UploadResponseHandler.java:61)
at com.microsoft.graph.core.requests.upload.UploadSliceRequestBuilder.put(UploadSliceRequestBuilder.java:69)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.uploadSlice(LargeFileUploadTask.java:207)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:131)
at com.microsoft.graph.core.tasks.LargeFileUploadTask.upload(LargeFileUploadTask.java:111)
[...]
To understand why, I wrote this Interceptor to log the requests and responses:
The text was updated successfully, but these errors were encountered:
kekolab
changed the title
LargeFileUploadTask does not add header Content-Length thus failing.
LargeFileUploadTask does not add header Content-Length (always?)
Feb 21, 2024
I believe that when creating the ok http request from the request information in the request adapter (see linked PR), the request body content length mechanism takes precedence. And because it's not down-casting the InputStream (unknown length) to the BinaryArrayInputStream (known length), it's not emitting the header.
The difference in behavior with the interceptor can be explained by the following lines:
when the interceptor is a network interceptor, the request headers and body have already been written. And the content length is missing due to the explanation above.
when the interceptor is an application interceptor, reading the stream to the end makes its length known, and the header is emitted. (that'd lead to memory pressure if the source was an actual large file, because it'd load the content of the file entirely in memory)
At this point I don't think there's much you can do besides waiting for a resolution on the PR I linked.
I couldn't manage to have the LargeFileUploadTask to work.
While debugging I noticed that LargeFileUploadTask.upload() does not add the Content-Length header to the request, as specified here
Expected behavior
Uploading a file
Actual behavior
Exception
Steps to reproduce the behavior
This is the code I use:
receiving this exception:
To understand why, I wrote this Interceptor to log the requests and responses:
and attached it to the OkHttpClientBuilder as a Network Interceptor:
thus obtaining the following log. Please note that:
The mistery is that if I attach the Interceptor as an Application Interceptor instead of an Network Interceptor (see here):
the content-length header magically appears (I'd think it is added when I rebuild the request) and the response is a 201/Created:
The text was updated successfully, but these errors were encountered: