question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SocketTimeoutException when trying to upload a file

See original GitHub issue

I am using fuel and fuel-android 1.12.0 I keep getting the following error when trying to upload a file.

This is the response:

<-- -1 (https://myurlhere.com)
Response : 
Length : 0
Body : (empty)
Headers : (0)

This is the result [Failure: java.net.SocketTimeoutException: Read timed out]

The file I am trying to upload is a bitmap that I am scaling then compressing:

val file = File.createTempFile( "file", ".png")
val fOut = FileOutputStream(file)

val height = (bitmap.height * 128 / bitmap.width)
val newBitmap = Bitmap.createScaledBitmap(bitmap, 128, height, true)
newBitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut)
fOut.flush()
fOut.close()

My request looks like this

Fuel.upload(url)
.source { request, url -> file }
.name { "file" }
.responseString { request, response, result -> 
    handler(response.statusCode)
}

I have tried changing the default timeout and readtimeout but that hasn’t had any affect.

This works in the emulator, however when I try it on a device I get the above response and result. I have tried different devices running different version of Android, from Android 21 to 26 all with the same outcome. It’s not even hitting the server that the url points to.

I was wondering if anyone had any suggestions on what I can do to fix this?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
jigarpatel17commented, Apr 25, 2018

@andrewmarmion It seems like you are compressing bitmap and it may reduce the quality. Was looking for a better way to do so and found below one which might help you in your case.

Fuel.upload("PUT YOUR WEB URL HERE",
        Method.POST, requestParam)
        .dataParts { request, url ->
            listOf(
                    //DataPart takes a file, and you can specify the name and/or type
                    DataPart(localVideoFile, "video"),
                    DataPart(localThumbnailFile, "thumbnail_image"))
        }
        .timeoutRead(10 * 60 * 1000) // this mean 10 minutes
        .timeout(10 * 60 * 1000) // this mean 10 minutes
        .responseString { request, response, result ->
            Log.d(TAG, "Upload response code: ${response.statusCode}")
        }
0reactions
SleeplessBytecommented, Aug 22, 2019

There is no maximum file upload size. Postman will limit the number of concurrent uploads automatically. Your browser limits it to ~6 (depending on the browser and version). Fuel does not limit it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.net.SocketTimeoutException error while trying to install ...
When trying to install an add-on *.jar file in Jira via the upload app button from the page ⚙ > Manage Apps >...
Read more >
android - Modify File Upload Socket Timeout and Exception
It attempts to add a more resilient network layer to the stack. Its been my experience they all try to pretend a connection...
Read more >
File Uploading - SocketTimeoutException: Read timed out
Hey, this usually occurs because of an unreliable internet connection. Also, note, 50mb is a large file! Are you on wifi or a...
Read more >
SocketTimeoutException:Read timed out error-check in file ...
sendRequest(userContext, inputBinder); where 'is' is the inputStream which has the file data that needs to be uploaded. ... I have tried to ...
Read more >
SonarQube report upload throwing SocketTimeOutException
When i try to execute sonar analysis on bigger project having more than 260 java source code files. the Sonar scanner completed the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found