Skip to content

Upload file to Sharepoint failed with 'Stream mark expired' when the inputstream is markSuppoted #2245

@ihudedi

Description

@ihudedi

Describe the bug

Hi,
When trying to upload file to sharepoint using
graphServiceClient.drives().byDriveId(driveId).items().byDriveItemId(getDriveItemIdFromRootPath(filePath)).content().put(fileContent);
Getting this exeception if the inputstream has markSupported
java.lang.RuntimeException: Stream mark expired.
at com.azure.storage.common.StorageInputStream.reset(StorageInputStream.java:396) [azure-storage-common-12.27.1.jar!/:12.27.1]
at com.microsoft.kiota.http.OkHttpRequestAdapter$1.writeTo(OkHttpRequestAdapter.java:907) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:62) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.RetryHandler.intercept(RetryHandler.java:226) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.RedirectHandler.intercept(RedirectHandler.java:158) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.HeadersInspectionHandler.intercept(HeadersInspectionHandler.java:70) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.UrlReplaceHandler.intercept(UrlReplaceHandler.java:52) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.ParametersNameDecodingHandler.intercept(ParametersNameDecodingHandler.java:79) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.UserAgentHandler.intercept(UserAgentHandler.java:84) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.graph.core.requests.middleware.GraphTelemetryHandler.intercept(GraphTelemetryHandler.java:64) [microsoft-graph-core-3.3.1.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.UrlReplaceHandler.intercept(UrlReplaceHandler.java:72) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.OkHttpRequestAdapter.getHttpResponseMessage(OkHttpRequestAdapter.java:716) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:275) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at com.microsoft.graph.drives.item.items.item.content.ContentRequestBuilder.put(ContentRequestBuilder.java:103) [microsoft-graph-6.20.0.jar!/:?]

If you go to OkHttpRequestAdapter you can see that when building the RequestBody there is method:
@OverRide
public void writeTo(@nonnull BufferedSink sink) throws IOException {
sink.writeAll(Okio.source(requestInfo.content));
if (!isOneShot()) {
requestInfo.content.reset();
}
}
This cause the upload failed.
Do you know why you reset this 2 times I saw in this file.
Thanks,
Itay

Expected behavior

Upload file should be suuceeded with inputstream with markSupported

How to reproduce

Hi,
When trying to upload file to sharepoint using
graphServiceClient.drives().byDriveId(driveId).items().byDriveItemId(getDriveItemIdFromRootPath(filePath)).content().put(fileContent);
Getting this exeception if the inputstream has markSupported
java.lang.RuntimeException: Stream mark expired.
at com.azure.storage.common.StorageInputStream.reset(StorageInputStream.java:396) [azure-storage-common-12.27.1.jar!/:12.27.1]
at com.microsoft.kiota.http.OkHttpRequestAdapter$1.writeTo(OkHttpRequestAdapter.java:907) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:62) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.RetryHandler.intercept(RetryHandler.java:226) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.RedirectHandler.intercept(RedirectHandler.java:158) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.HeadersInspectionHandler.intercept(HeadersInspectionHandler.java:70) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.UrlReplaceHandler.intercept(UrlReplaceHandler.java:52) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.ParametersNameDecodingHandler.intercept(ParametersNameDecodingHandler.java:79) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.UserAgentHandler.intercept(UserAgentHandler.java:84) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.graph.core.requests.middleware.GraphTelemetryHandler.intercept(GraphTelemetryHandler.java:64) [microsoft-graph-core-3.3.1.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.middleware.UrlReplaceHandler.intercept(UrlReplaceHandler.java:72) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201) [okhttp-4.12.0.jar!/:?]
at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154) [okhttp-4.12.0.jar!/:?]
at com.microsoft.kiota.http.OkHttpRequestAdapter.getHttpResponseMessage(OkHttpRequestAdapter.java:716) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:275) [microsoft-kiota-http-okHttp-1.7.0.jar!/:?]
at com.microsoft.graph.drives.item.items.item.content.ContentRequestBuilder.put(ContentRequestBuilder.java:103) [microsoft-graph-6.20.0.jar!/:?]

If you go to OkHttpRequestAdapter you can see that when building the RequestBody there is method:
@OverRide
public void writeTo(@nonnull BufferedSink sink) throws IOException {
sink.writeAll(Okio.source(requestInfo.content));
if (!isOneShot()) {
requestInfo.content.reset();
}
}
This cause the upload failed.
Do you know why you reset this 2 times I saw in this file.
Thanks,
Itay

SDK Version

6.22.0

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_

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugA broken experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions