AndroidNetworking.upload(getString(R.string.base_url) + getString(R.string.account) + "/" + getString(R.string.image))
.addMultipartFile("profile_image", new File(filePath))
.addHeaders(Headers.BaseHeader.getHeaders())
.addMultipartParameter("customer_id", userId)
.setTag("updateProfileImage")
.setPriority(Priority.HIGH)
.build()
.setUploadProgressListener(new UploadProgressListener() {
@Override
public void onProgress(long bytesUploaded, long totalBytes) {
imageView.progress((int) ((bytesUploaded / totalBytes) * 100));
}
})
.getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "onResponse: " + response.toString());
imageView.progress(100);
BaseModel
if (baseModel.isSuccess()) {
imageView.showContent(baseModel.getData());
} else {
imageView.showError(baseModel.getError());
}
}
@Override
public void onError(ANError error) {
Log.d(TAG, "onError: " + error.getErrorDetail());
imageView.progress(0);
imageView.showError(error.getErrorDetail() + "\n" + error.getErrorCode());
}
});
D/OkHttp: --31de0c5b-94b2-4a17-807f-126190d47ebc--
04-09 15:08:29.298 18074-18862/com.beinmedia.kshw D/OkHttp: --> END POST (32835-byte body)
04-09 15:08:29.325 18074-18074/com.beinmedia.kshw I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@67c4538 time:2791738
04-09 15:08:29.359 18074-18862/com.beinmedia.kshw D/OkHttp: <-- HTTP FAILED: java.net.ProtocolException: unexpected end of stream
can u tell me the exact error you are getting?
@amitshekhariitbhu i'm trying to use upload method first i'm selecting image and give to the method by .addMultipartFile("profile_image", new File(filePath)) but when it start upload it give this error
D/OkHttp: --31de0c5b-94b2-4a17-807f-126190d47ebc--
04-09 15:08:29.298 18074-18862/com.beinmedia.kshw D/OkHttp: --> END POST (32835-byte body)
04-09 15:08:29.325 18074-18074/com.beinmedia.kshw I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@67c4538 time:2791738
04-09 15:08:29.359 18074-18862/com.beinmedia.kshw D/OkHttp: <-- HTTP FAILED: java.net.ProtocolException: unexpected end of stream
@amitshekhariitbhu and also it did not connect to server so the request it did not go from my device
@amitshekhariitbhu and also it did not connect to server so the request it did not go from my device
@amitshekhariitbhu i think it's about D/OkHttp: Content-Length: 1061356 :\ dose it have a maximum content-Length
I too think it's about OkHttp
@amitshekhariitbhu what is the version u use in OkHttp in your library
@amitshekhariitbhu i try to search some people said its about content length so is there any way to change it
It seems it has been internally handled in OkHttp.
ok @amitshekhariitbhu how i can add file with key in post method this will help also
@amitshekhariitbhu if its possible .addFileBody("profile_image", new File(filePath)) like this
As of now, there is no way to do so in the library, but the multipart is POST request only.
@amitshekhariitbhu is there any way to fix multipart issue :(
I will check it and inform u if possible.
@amitshekhariitbhu thanks my application is stoped coz of this problem i'm trying from morning and don't want to use another libs this is very nice thanks 👍
can you tell me the value of error.getErrorCode().
Error code 0
On Sun, Apr 9, 2017 at 4:28 PM AMIT SHEKHAR notifications@github.com
wrote:
can you tell me the value of error.getErrorCode().
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/amitshekhariitbhu/Fast-Android-Networking/issues/106#issuecomment-292785862,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AHMF-_y6DgmjM7A-6KchznrBUuclPbaCks5ruNzzgaJpZM4M39x8
.
@amitshekhariitbhu any update bro
@geniusforapp you can get my mail which is publicly available, please send me the complete request like URL, file to be upload, header. I will test and fix it as soon as possible.
The issue is in logging the okHttp response and request, so do not use body level logging if you are uploading.
@amitshekhariitbhu thanks bro it worked very will thanks for your help 👍
hey.bro,how can I control to set body level if uploading,otherwise other request should use this level to printf the log,thx
@zongkang currently you can not customize it for each request.
Hi @amitshekhariitbhu ,I'm trying to use AndroidNetworking.download(url,dirPath,fileName) to download a file from server but I got this Error "com.androidnetworking.error.ANError: com.androidnetworking.error.ANError: java.net.ProtocolException: unexpected end of stream". Can you help me please?
Have you enable body level logging?
How could I enable it ?
It's occurs in enabled mode.
I used this method:
private OkHttpClient getConfigOkHttpClient() {
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC);
return new OkHttpClient.Builder()
.addInterceptor(httpLoggingInterceptor)
.retryOnConnectionFailure(true)
.build();
}
And I called it here:
AndroidNetworking.download(getUrl, path, file)
.setTag(TAG_ANDROID_NETWORKING)
.setPriority(Priority.HIGH)
.setOkHttpClient(getConfigOkHttpClient())
.setPercentageThresholdForCancelling(0)
.build();
Try removing the logging.
Hi, I removed it but I got the same error!!
Hi Amit,
I am also getting this error while uploading file on server:
com.androidnetworking.error.ANError: java.net.ProtocolException: unexpected end of stream
How can I resolve this error. Can you please tell me?
@bonjourrohit89 did you resolve it ? also have this issue
@winnerawan Yes I have resolved same, as @amitshekhariitbhu said we get this error when we enable logging. I had also enabled body level logging in my Application class like:
// if (BuildConfig.DEBUG) {
// AndroidNetworking.enableLogging(HttpLoggingInterceptor.Level.BODY);
// }
After commenting this code, my code working properly.
also i have same issue with upload method.
com.androidnetworking.error.ANError: java.net.ProtocolException: unexpected end of stream
or didn't get any response from server.
please solve the problem...
Can I upload multiple images with multiple keys and values using your library?
I have noticed there is only one image you can upload at a time.
Please answer
Just comment out the bellow code or off the debug. It works for me
//if (BuildConfig.DEBUG) {
// AndroidNetworking.enableLogging(HttpLoggingInterceptor.Level.BODY)
// }/
Just comment out the bellow code or off the debug. It works for me
//if (BuildConfig.DEBUG) {
// AndroidNetworking.enableLogging(HttpLoggingInterceptor.Level.BODY)
// }/
Most helpful comment
The issue is in logging the okHttp response and request, so do not use body level logging if you are uploading.