wkh237 / react-native-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.61k stars 1.6k forks source link

Android: Unexpected end of stream - bugs after updating SDK #150

Open plougsgaard opened 8 years ago

plougsgaard commented 8 years ago

Problem

I am making presigned putObject requests like this (to AWS S3):

RNFetchBlob.fetch(
  'PUT',
  someUrl,
  { 'Content-Type': 'application/octet-stream' },
  RNFetchBlob.wrap(pathToImageFile)
)

And it worked perfectly until I updated my Android SDK (to these versions):

I don't know what the versions were before and I don't think I can downgrade them either. Any clue where to start?

Edit: PUTing with httpie still works as it did before.

http put someUrl Content-Type:application/octet-stream < pathToImageFile

Versions

This is what the dev tools give me before crashing the app with the unexpected end of stream error.

timeout
RNFetchBlob error when sending request : unexpected end of stream
timeout

Stacktrace from adb logcat

10-10 20:16:24.081  6042  6982 W System.err: java.net.SocketTimeoutException: timeout
10-10 20:16:24.083  6042  6982 W System.err:    at okio.Okio$3.newTimeoutException(Okio.java:210)
10-10 20:16:24.084  6042  6982 W System.err:    at okio.AsyncTimeout.exit(AsyncTimeout.java:277)
10-10 20:16:24.084  6042  6982 W System.err:    at okio.AsyncTimeout$1.write(AsyncTimeout.java:186)
10-10 20:16:24.084  6042  6982 W System.err:    at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:171)
10-10 20:16:24.084  6042  6982 W System.err:    at okio.RealBufferedSink.write(RealBufferedSink.java:41)
10-10 20:16:24.084  6042  6982 W System.err:    at okhttp3.internal.http.Http1xStream$FixedLengthSink.write(Http1xStream.java:282)
10-10 20:16:24.084  6042  6982 W System.err:    at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:171)
10-10 20:16:24.084  6042  6982 W System.err:    at okio.RealBufferedSink.write(RealBufferedSink.java:91)
10-10 20:16:24.084  6042  6982 W System.err:    at com.RNFetchBlob.RNFetchBlobBody.pipeStreamToSink(RNFetchBlobBody.java:268)
10-10 20:16:24.084  6042  6982 W System.err:    at com.RNFetchBlob.RNFetchBlobBody.writeTo(RNFetchBlobBody.java:119)
10-10 20:16:24.084  6042  6982 W System.err:    at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:47)
10-10 20:16:24.084  6042  6982 W System.err:    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-10 20:16:24.084  6042  6982 W System.err:    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-10 20:16:24.084  6042  6982 W System.err:    at com.RNFetchBlob.RNFetchBlobReq$1.intercept(RNFetchBlobReq.java:298)
10-10 20:16:24.084  6042  6982 W System.err:    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-10 20:16:24.084  6042  6982 W System.err:    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
10-10 20:16:24.084  6042  6982 W System.err:    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-10 20:16:24.085  6042  6982 W System.err:    at com.RNFetchBlob.RNFetchBlobReq$2.intercept(RNFetchBlobReq.java:306)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.RealCall.access$100(RealCall.java:33)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:120)
10-10 20:16:24.085  6042  6982 W System.err:    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
10-10 20:16:24.086  6042  6982 W System.err:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
10-10 20:16:24.086  6042  6982 W System.err:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
10-10 20:16:24.086  6042  6982 W System.err:    at java.lang.Thread.run(Thread.java:818)

Edit 2016-10-11

The same code is working on iOS (10.0.2).

wkh237 commented 8 years ago

Not sure how to reproduce it, but looks like it happens when using fixed length request. I will look into it.

hujiudeyang commented 7 years ago

Android: RNFetchBlobBody.java : 199: header += "Content-Disposition: form-data; name=" + name + "; filename=" + field.filename + "\r\n";

IOS: RNFetchBlobReqBuilder.m: 203: [formData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", name, filename] dataUsingEncoding:NSUTF8StringEncoding]];

IOS have '\"' But Android not have。

manavdahra commented 7 years ago

@wkh237 Did you find anything ?

hujiudeyang commented 7 years ago

@havishhuda

it worked for me

RNFetchBlobBody.java : 199: header += "Content-Disposition: form-data; name=\"" + name + "\"; filename=\"" + field.filename + "\"\r\n";

Schwarzenegger commented 7 years ago

Hi @hujiudeyang facing the same problem here.

Everything works fine on android 5.0 and 5.1, IOs works fine too.

But on 6.0+ I have the same problem.

[Error: unexpected end of stream]

Did you solve this?

Schwarzenegger commented 7 years ago

@wkh237 did you test this, or have some kinda of fix?

dancomanlive commented 6 years ago

screen shot 2018-06-05 at 1 20 58 pm

The error occurs in react-native-fetch-blob/index.js

I am using Android Oreo 8.0 on Galaxy S9 and Oreo 8.1 on PixelXL2 RN 0.55.0 React 16.3.2 react native fetch blob 0.10.8