-
-
Notifications
You must be signed in to change notification settings - Fork 693
Troubleshooting Procedure
You know, these days when something doesn't work, the first thought of many people is the app is bugged
, so you're engaged to provide some insights and analysis. Since you are using a third party library, you may be tempted to think
followed the examples, run my app, it doesn't work, so its' it's a library bug for sure
wrong
, but don't worry and keep reading. This will help you spot where the real issue is step by step, methodically, like we engineers do π·.
If you find this helpful, consider sponsoring the project by pressing the
Sponsor
button on the top right of this page.
Let's face it, doing network programming is not easy as there are many things that can go wrong, but if upload doesn't work out of the box:
Upload works with curl/postman + your server | Upload works on your app + your server | Solution |
---|---|---|
π΄ | π΄ | Check your internet connectivity to the server and your server. Fix eventual issues and then retry. |
π’ | π΄ | Check your app for bugs, be sure to have followed the examples. If still in trouble, read the next paragraph |
π’ | π’ | All right, let's have some fun! |
When making tests, be sure to make the exact same upload when using curl/postman and your app. For example, if you upload a 200MB file from your app, be sure to upload the same amount of data or the same file using curl or postman and to send the same parameters and headers
Don't know curl? It's a swiss army knife for networking. Learning it will advance your career. It's the tool I use the most when doing networking stuff and it's amazing. You can start from the examples provided here: https://github.com/gotev/android-upload-service/wiki/Upload-Service-Demo-Server
-
Is the server URL correct?
-
NO
: That may be the issue -
YES
: Go to the next question
-
-
Is the server URL reachable from your device?
-
NO
: Check if there are firewalls or other kind of restrictions between your device and the server. -
YES
: Go to the next question.
-
-
Have you properly set up the request with all the headers, parameters and files that the server expects?
-
NO
: That may be the issue -
YES
: Go to the next question
-
-
Is your server using HTTPS?
-
NO
: Be sure to have cleartext requests enabled for your app, otherwise Android may block you. -
YES
: Be sure to have valid and trusted certificates on your server. You can easily check by visiting your server address from Google Chrome or Mozilla Firefox. If a security message pops up, then something is wrong with your certificates. Fix that. If you just want to ignore that exception while you are testing in your own environment, go in the advanced topics of the wiki and see how to enable self-signed certificates.
-
-
Are you sure you are starting the upload from your app? Can you see the library debug logs?
-
NO
: Enable library debug logs. 4.x versions have them enabled by default for debug builds. Check the wiki pages and follow examples given in the wiki and demo apps in theexamples
directory. -
YES
: go ahead to the next paragraph
-
It's time to setup the Upload Service testbed. Follow those instructions: https://github.com/gotev/android-upload-service/wiki/Upload-Service-Testbed, then get back to this page. Can't make the testbed work as described? Report all the details in an issue.
Upload works on demo app on emulator + demo server | Upload works on demo app on your device + demo server | Upload works on your app + demo server | Upload works on your app + your server | Solution |
---|---|---|---|---|
π’ | π΄ | -- | -- | Check your device and your network. Ensure it's on the same WiFi network as your computer and there's no client isolation between the two |
π’ | π’ | π΄ | -- | Check your app for bugs and eventually change the demo server's responses to match what your app expects. If still no luck, create an empty project wthout your business specific stuff and keep things to minimal while trying to replicate the same behavior. If you can replicate the same problem, open an issue with all the details and the demo project |
π’ | π’ | π’ | π΄ | The problem is in the network between you and the server or in the server itself. |
π’ | π’ | π’ | π’ | All right, let's have some fun! |
When you upload a file to a server, those are some of the variables which play a significant role:
-
android background execution limits
: Android imposes background execution limits to conserve system resources. If your app is running in the background, it may have limited access to CPU and network resources, which could affect upload speeds. -
battery optimization
: If your app has been optimized for battery life by Android, it may have restrictions on background network access, which could impact upload speeds. -
network latency and packet loss
: Slow upload speeds or failed uploads can be influenced by the quality and congestion of your Wi-Fi network. If the network is busy or has limited bandwidth, it can result in slower upload speeds. It's also possible that the network conditions change between the initial upload and the resumed upload, causing variations in speed. -
network bandwidth
: Some mobile carriers and ISPs implement data throttling, which can limit the speed of certain types of traffic, including uploads. It's worth checking if your network provider is imposing any throttling. -
upload file size
: The server receiving the uploads may have limitations on size and rate at which it can accept data. Some servers limit the upload speed per connection to prevent abuse or to ensure fair resource allocation. - server socket timeout time
-
server certificates
: the upload may fail because of poor server-side certificates which cannot be properly validated by Android. Self-signed certificates and certificates issued by a non well established CA will almost surely cause you problems. - proxies
- firewalls
When you encounter a SocketTimeout
or a Broken Pipe
exception, it means one or more of the following (this is not meant to be an exhaustive list):
- the amount of data you're trying to send to your server takes longer than the maximum allowed time to complete the request, due to file size, network conditions or the two combined
- something between you and your server is closing the connection prematurely
- the server certificate is not good
This may happen in two scenarios:
- While starting the upload: it means you have set big notification icons which exceeds system limits or you have set large payloads as parameter values. Use smaller icons and do not put big data as parameter values. You can however have whatever file size for the upload, as files are referenced by path and read only when the actual upload happens.
- After you have received the response from your server: read below
The library has not been designed to handle big responses from the server after an upload, so at the current state of the art, it's normal you're getting this error.
Big responses cannot be passed in intents by Android design, to keep the app responsive. The whole library is based on intents to pass data to and from the service.
Normally, you shouldn't return big responses as a result of a completed upload, so the first thing to do is to avoid doing that.
From a library design perspective, handling big responses means downloading the response body got from the server in a temporary location and then returning the path to the response payload in the intent. This could work for a minority of use cases, but it will be an overkill in the vast majority of the cases when the response is a simple json or plain text. I'm open to suggestions and considerations.
java.lang.SecurityException: Permission Denial: opening provider com.some.provider requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
It means you forgot to ask for some read permissions. Check this example.
If something is not working as expected when you perform an upload and you can't figure out where the problem really is, dump the network traffic and analyze requests and responses with Wireshark. An useful free tool to dump the network traffic directly on your device is tPacketCapture. It creates a .pcap file in /sdcard/Android/data/jp.co.taosoftware.android.packetcapture/files/
ready to be transferred to your computer (you can use Dukto for that), which you can open with Wireshark. Top 10 reasons to learn Wireshark.
Permissions needed by the library are listed in the manifest. As stated here, only android.permission.WRITE_EXTERNAL_STORAGE
is considered dangerous, so you have to make sure that your apps has that permission granted. It's needed to be able to select files for upload and delete successfully uploaded files.
If your server uses modern certificates which support TLS 1.2, you may have problems on older Android devices. This is due to the fact that TLS 1.2 is not enabled by default on those devices even if it's implemented, so you may have SSLHandshakeException
. Check this issue to solve this problem. Bear in mind the solution may not work on all devices, as hardwares which runs Android prior to 5.0 may not have the capabilities required by TLS 1.2.