Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multipart upload fail when using on Fast Android Networking #110

Closed
DE-DuyTran opened this issue Sep 6, 2019 · 9 comments
Closed

Multipart upload fail when using on Fast Android Networking #110

DE-DuyTran opened this issue Sep 6, 2019 · 9 comments

Comments

@DE-DuyTran
Copy link

I used ChuckInterceptor on FAN and can't upload file via multipart.

    val okHttpClient = OkHttpClient().newBuilder()
            .connectTimeout(120, TimeUnit.SECONDS)
            .readTimeout(120, TimeUnit.SECONDS)
            .addInterceptor(ChuckerInterceptor(this))
            .writeTimeout(120, TimeUnit.SECONDS)
            .build()

    AndroidNetworking.initialize(applicationContext, okHttpClient)

Remove Interceptor is worked fine.

@cortinico
Copy link
Member

Hey @DE-DuyTran
Thanks for the report. Can you please provide more context?

  • What does can't upload file via multipart?
  • Are you getting a HTTP error code?
  • Do you have any stacktrace to share?
  • Is the app crashing?
  • Is this issue happening only for multipart requests?

Ideally if you could provide also a sample project where we can reproduce the issue, would be awesome.

@cortinico cortinico added the incomplete This issue needs more data in order to be triaged label Sep 8, 2019
@vbuberen
Copy link
Collaborator

vbuberen commented Jan 8, 2020

Hey @DE-DuyTran
Do you still experience this issue?
If so, could you provide details requested by @cortinico in the message above?

@DE-DuyTran
Copy link
Author

@cortinico @vbuberen
Sorry for very late reply...
This is my answer.

  • What does can't upload file via multipart?
    I upload Image file (JPEG) to attach with json body.

  • Are you getting a HTTP error code?
    What i receive from LogCat
    "com.androidnetworking.error.ANError: java.net.ProtocolException: unexpected end of stream"
    "java.net.ProtocolException: unexpected end of stream"

  • Do you have any stacktrace to share?
    handlerError:170, BaseDisposable (xxxx.model.base)
    access$handlerError:40, BaseDisposable (xxxx.model.base)
    accept:92, BaseDisposable$startWithoutCheckNetwork$1 (xxxx.model.base)
    accept:40, BaseDisposable$startWithoutCheckNetwork$1 (xxxx.model.base)
    onError:114, ObservableDoOnEach$DoOnEachObserver (io.reactivex.internal.operators.observable)
    checkTerminated:276, ObservableObserveOn$ObserveOnObserver (io.reactivex.internal.operators.observable)
    drainNormal:172, ObservableObserveOn$ObserveOnObserver (io.reactivex.internal.operators.observable)
    run:252, ObservableObserveOn$ObserveOnObserver (io.reactivex.internal.operators.observable)
    run:119, HandlerScheduler$ScheduledRunnable (io.reactivex.android.schedulers)
    handleCallback:873, Handler (android.os)
    dispatchMessage:99, Handler (android.os)
    loop:201, Looper (android.os)
    main:6806, ActivityThread (android.app)
    invoke:-1, Method (java.lang.reflect)
    run:547, RuntimeInit$MethodAndArgsCaller (com.android.internal.os)
    main:873, ZygoteInit (com.android.internal.os)

  • Is the app crashing?
    It's no crashing.

  • Is this issue happening only for multipart requests?
    I'm not yet test for other case.

@vbuberen
Copy link
Collaborator

vbuberen commented Jan 9, 2020

Thanks a lot for such a detailed input.
I searched through issues in Fast Android Networking and found an issue, which looks quite similar to what you described: amitshekhariitbhu/Fast-Android-Networking#464
If it happens to be the same issue, it seems that it is not Chucker, but Fast Android Networking.

@vbuberen vbuberen added help wanted Extra attention is needed and removed incomplete This issue needs more data in order to be triaged help wanted Extra attention is needed labels Jan 9, 2020
@vbuberen
Copy link
Collaborator

I guess, we can close it, since no other reports here.

@olegsvs
Copy link

olegsvs commented Mar 29, 2021

HI @vbuberen
Similar with ktor(1.5.0/1.5.2) and multipart upload
with chucker(3.4.0):

I/System.out: File exists: IMG_20210329_084101.jpg, size=31660
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] REQUEST: https://*.*/blabla
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] METHOD: HttpMethod(value=PUT)
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] COMMON HEADERS
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] -> Accept: application/json
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] -> Accept-Charset: UTF-8
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] -> Authorization: blabla
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] -> Cache-Control: private
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] CONTENT HEADERS
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] -> Content-Length: 32085
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] -> Content-Type: multipart/form-data; boundary=-681f0d6a310571652db4fcd412f01206-38c3e46b45ddb43479b39dfc-30c76d864e3
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] BODY Content-Type: multipart/form-data; boundary=-681f0d6a310571652db4fcd412f01206-38c3e46b45ddb43479b39dfc-30c76d864e3
I/i.k.c.HttpClient.log: [OkHttp https://*.*/...] BODY START
I/i.k.c.HttpClient.log: [OkHttp https://*.*/...] [request body omitted]
I/i.k.c.HttpClient.log: [OkHttp https://*.*/...] BODY END
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-3] REQUEST https://*.*/blabla failed with exception: java.net.ProtocolException: unexpected end of stream

 Caused by: java.net.ProtocolException: unexpected end of stream
	at okhttp3.internal.connection.Exchange$RequestBodySink.close(Exchange.kt:239)
	at okio.RealBufferedSink.close(RealBufferedSink.kt:268)
	at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:60)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:82)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
	at com.chuckerteam.chucker.api.ChuckerInterceptor.intercept(ChuckerInterceptor.kt:114)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
	at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:197)
	at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:502)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
	at java.lang.Thread.run(Thread.java:923)

without chucker ok:

I/System.out: File exists: IMG_20210329_084101.jpg, size=31660
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] REQUEST: https://*.*/blabla
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] METHOD: HttpMethod(value=PUT)
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] COMMON HEADERS
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] -> Accept: application/json
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] -> Accept-Charset: UTF-8
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] -> Authorization: blabla
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] -> Cache-Control: private
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] CONTENT HEADERS
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] -> Content-Length: 32085
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] -> Content-Type: multipart/form-data; boundary=6538ee3e2b1702c55849d34-6c66f14c702565c15406a4a4-7b253755310821926b054
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] BODY Content-Type: multipart/form-data; boundary=6538ee3e2b1702c55849d34-6c66f14c702565c15406a4a4-7b253755310821926b054
I/i.k.c.HttpClient.log: [OkHttp https://*.*/...] BODY START
I/i.k.c.HttpClient.log: [OkHttp https://*.*/...] [request body omitted]
I/i.k.c.HttpClient.log: [OkHttp https://*.*/...] BODY END
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] RESPONSE: 200 OK
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] METHOD: HttpMethod(value=PUT)
I/i.k.c.HttpClient.log: [DefaultDispatcher-worker-1] FROM: https://*.*/blabla

method for upload:

suspend fun attachFile(
        context: Context,
        uri: Uri,
        fileName: String,
        fileSizeByte: Long
    ) {
        client.request<HttpResponse> {
            apiUrl("blabla")
            method = HttpMethod.Put
            body = MultiPartFormDataContent(
                formData {
                    appendInput(
                        key = "encode-base64-scan",
                        headers = Headers.build {
                            append(HttpHeaders.ContentLength, fileSizeByte)
                            append(HttpHeaders.ContentDisposition, "filename=${fileName}")
                        },
                        size = fileSizeByte
                    ) {
                        buildPacket {
                            context.contentResolver.openInputStream(uri)!!.use {
                                writeFully(it.readBytes())
                            }
                        }
                    }
                }
            )
        }
    }

https://github.com/ChuckerTeam/chucker/blob/3.x/library/src/main/java/com/chuckerteam/chucker/api/ChuckerInterceptor.kt#L114

@cortinico
Copy link
Member

HI @vbuberen
Similar with ktor(1.5.0/1.5.2) and multipart upload

Please open a new issue.
Also I'm unsure how KTor is relevant here as Chucker works only with OkHTTP

@MiSikora
Copy link
Contributor

Also I'm unsure how KTor is relevant here as Chucker works only with OkHTTP

You can install OkHttp as an underlying client.

@cortinico
Copy link
Member

You can install OkHttp as an underlying client.

TIL :O

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants