Skip to content

Problem with file uploads #1190

Description

@kramano

Description of the Issue

After upgrading box sdk from 3.8 to 4.2 we started get exceptions during file uploads.
The same code works fine with version 3.8 but doesn't work with 4.2.

Steps to Reproduce

Here is the repo with the minimal code to reproduce the issue: https://github.com/kramano/fileupload-box-issue
Master is with the latest version of the box sdk (4.2.0). Also has a branch with 3.8 version of the sdk and exactly same code where everything works fine: https://github.com/kramano/fileupload-box-issue/tree/box-sdk-3.8

Expected Behavior

File uploaded successfully.

Error Message, Including Stack Trace

java.lang.RuntimeException: com.box.sdk.BoxAPIException: Couldn't connect to the Box API due to a network error. Request
Request{method=POST, url=https://upload.box.com/api/2.0/files/content, headers=[Authorization:Bearer <token>, User-Agent:Box Java SDK v4.2.0 (Java 17.0.7), X-Box-UA:agent=box-java-sdk/4.2.0; env=Java/17.0.7, Accept-Charset:utf-8, Content-Type:multipart/form-data; boundary=da39a3ee5e6b4b0d3255bfef95601890afd80709]}
	at com.demo.FileUploadServlet.lambda$doPost$0(FileUploadServlet.java:55)
	at org.apache.commons.io.function.IOIterator.forEachRemaining(IOIterator.java:65)
	at com.demo.FileUploadServlet.doPost(FileUploadServlet.java:44)
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:520)
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:587)
	at org.eclipse.jetty.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1410)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
	at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1665)
	at org.eclipse.jetty.websocket.servlet.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:170)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:527)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:131)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:578)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:223)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1570)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1381)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1543)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1303)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:149)
	at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:51)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
	at org.eclipse.jetty.server.Server.handle(Server.java:563)
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
	at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:969)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1194)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1149)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: com.box.sdk.BoxAPIException: Couldn&apos;t connect to the Box API due to a network error. Request
Request{method=POST, url=https://upload.box.com/api/2.0/files/content, headers=[Authorization:Bearer <token>, User-Agent:Box Java SDK v4.2.0 (Java 17.0.7), X-Box-UA:agent=box-java-sdk/4.2.0; env=Java/17.0.7, Accept-Charset:utf-8, Content-Type:multipart/form-data; boundary=da39a3ee5e6b4b0d3255bfef95601890afd80709]}
	at com.box.sdk.BoxAPIConnection.executeOnClient(BoxAPIConnection.java:1260)
	at com.box.sdk.BoxAPIConnection.execute(BoxAPIConnection.java:1249)
	at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:610)
	at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:380)
	at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:347)
	at com.box.sdk.BoxFolder.uploadFile(BoxFolder.java:558)
	at com.box.sdk.BoxFolder.uploadFile(BoxFolder.java:461)
	at com.demo.FileUploadServlet.lambda$doPost$0(FileUploadServlet.java:52)
	... 39 more
Caused by: java.net.ProtocolException: expected 8151 bytes but received 8192
	at okhttp3.internal.connection.Exchange$RequestBodySink.write(Exchange.kt:214)
	at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.kt:255)
	at okio.RealBufferedSink.write(RealBufferedSink.kt:185)
	at com.box.sdk.RequestBodyFromStream.writeTo(RequestBodyFromStream.java:45)
	at okhttp3.MultipartBody.writeOrCountBytes(MultipartBody.kt:157)
	at okhttp3.MultipartBody.writeTo(MultipartBody.kt:93)
	at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:59)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
	at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
	at com.box.sdk.BoxAPIConnection.executeOnClient(BoxAPIConnection.java:1258)
	... 46 more

Versions Used

Java SDK :v4.2.0
Java: 17.0.7

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugAdded to issues that describes SDK bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions