Fast-Android-Networking icon indicating copy to clipboard operation
Fast-Android-Networking copied to clipboard

ConnectionShutdownException Error

Open MOhsain opened this issue 4 years ago • 4 comments

com.androidnetworking.error.ANError: com.androidnetworking.error.ANError: okhttp3.internal.http2.ConnectionShutdownException

I'm facing this error. i just send file to the server. Please help me

MOhsain avatar Jun 03 '20 06:06 MOhsain

com.androidnetworking.error.ANError: okhttp3.internal.http2.ConnectionShutdownException

me to .. i have increase network with

        val client = OkHttpClient.Builder()
                .connectTimeout(10, TimeUnit.SECONDS)
                .writeTimeout(10, TimeUnit.SECONDS)
                .readTimeout(30, TimeUnit.SECONDS)
                .build()

        AndroidNetworking.initialize(applicationContext, client)

but the error still appear on uploading image to server i have tested with postman and its work but when i implement with

AndroidNetworking.upload(UPLOAD_FOTO)

dunno why, i get the error.

                AndroidNetworking.upload(UPLOAD_FOTO)
                        .addMultipartFile("file", imageFile) //.addMultipartParameter("key","value")
                        //.setTag("uploadTest")
                        .setPriority(Priority.HIGH)
                        .build()
                        .setUploadProgressListener { bytesUploaded, totalBytes ->
                            // do anything with progress
                            tv_upload_foto.text = "uploading foto : ${((bytesUploaded / totalBytes) * 100)} %"
                        }
                        .getAsString(object : StringRequestListener {
                            override fun onResponse(response: String) {
                                Toast.makeText(this@DashboardActivityK, response, Toast.LENGTH_SHORT).show()
                                Log.d(TAG_LOG, """
                                    response
                                    $response
                                """.trimIndent())
                            }

                            override fun onError(anError: ANError) {
                                Toast.makeText(this@DashboardActivityK, anError.message, Toast.LENGTH_SHORT).show()
                                Log.d(TAG_LOG, """
                                    \n
                                    ${anError.message}
                                """.trimIndent())
                            }
                        })
            } catch (e: FileNotFoundException) {
                e.printStackTrace()
                Toast.makeText(this@DashboardActivityK, "Something went wrong", Toast.LENGTH_LONG).show()
            }
        } else {
            Toast.makeText(this@DashboardActivityK, "You haven't picked Image", Toast.LENGTH_LONG).show()
        }

thanks in advance

yogithesymbian avatar Jun 24 '20 11:06 yogithesymbian

AndroidNetworking.upload("https://webaddress-goes_here.com/upload.php")

I presume upload_photo is a web address ?

What response do you get from the server, turning on PHP errors, etc can you browse the same page with no errors ?

1stmetro avatar Jun 24 '20 11:06 1stmetro

already solved by added android:requestLegacyExternalStorage="true" in manifest

before i always get ConnectionShutdownException

before upload.kt if (requestCode == 0 && resultCode == Activity.RESULT_OK && data !=null ) {

when i change upload.kt to if ( resultCode == Activity.RESULT_OK ) {

the error permission have appear Exception 'open failed: EACCES (Permission denied)' on Android so i added the manifest

uploading success then i change revert change my upload.kt

its work fine

i dunno why about this check data !=null make the error

but already solved thanks in advance

my code now

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (requestCode == 0 && resultCode == Activity.RESULT_OK && data !=null ) {
            try {
                selectedPhotoUri = data.data

                val bitmap = MediaStore.Images.Media.getBitmap(applicationContext?.contentResolver, selectedPhotoUri)
                btn_select_circle_image.setImageBitmap(bitmap)

                btn_select_photo.alpha = 0f

                //==========================
                //final InputStream imageStream = //getContentResolver().openInputStream(selectedImageUri);
                //final Bitmap selectedImage = //BitmapFactory.decodeStream(imageStream);
                //imgUser.setImageBitmap(selectedImage);
                val imagepath = selectedPhotoUri?.let {
                    getRealPathFromURI(it, this)
                }
                val imageFile = File(imagepath)

                Log.d(TAG_LOG, """
                    \n
                    selectedPhotoUri : $selectedPhotoUri
                    imagePath : $imagepath
                    imagefile : $imageFile
                """.trimIndent())

                AndroidNetworking.upload(UPLOAD_FOTO)
//                        .addMultipartFile("file", imageFile)
                        .addMultipartFile("file", imageFile)
//                        .addMultipartParameter("file", imageFile.toString())
                        .setTag("uploadImage")
                        .setPriority(Priority.HIGH)
                        .build()
                        .setUploadProgressListener { bytesUploaded, totalBytes ->
                            // do anything with progress
                            tv_upload_foto.text = "uploading foto : ${((bytesUploaded / totalBytes) * 100).toInt()}"
                        }
                        .getAsJSONObject(object : JSONObjectRequestListener{
                            override fun onResponse(response: JSONObject?) {
                                val jsonArray = response?.getString("url")
                                Log.d(TAG_LOG, """
                                    response
                                    $response
                                    j
                                    $jsonArray
                                """.trimIndent())
                            }

                            override fun onError(anError: ANError?) {
                                Toast.makeText(this@DashboardActivityK, anError?.message, Toast.LENGTH_SHORT).show()
                                Log.d(TAG_LOG, """
                                    \n
                                    ${anError?.message}
                                """.trimIndent())
                            }

                        })
            } catch (e: FileNotFoundException) {
                e.printStackTrace()
                Toast.makeText(this@DashboardActivityK, "Something went wrong", Toast.LENGTH_LONG).show()
            }
        } else {
            Toast.makeText(this@DashboardActivityK, "You haven't picked Image", Toast.LENGTH_LONG).show()
        }
}

yogithesymbian avatar Jun 24 '20 13:06 yogithesymbian

Thank you #yogithesymbian I,ve solved by added android:requestLegacyExternalStorage="true" in manifest

forkanju avatar Aug 19 '21 05:08 forkanju