RAL
RAL

Reputation: 17

Post multipart imagens using Fast Android Networking

I'm using Fast Android Networking library in my project.

My goal is to make a post with multiple parameters, like the image above.

enter image description here

What I'm trying to acomplish is to send a file with image from my app to a webservice.

Here is my code:

Kotlin:

fun postFotosFeridas() {
    AndroidNetworking.post("http://192.168.254.80/F3M.MpDS.API/api/F3MMpDSImages/")
            .addHeaders("Authorization", Token_Type + " " + New_Token)
            .addHeaders("Content-Type", "multipart/form-data")
            .addBodyParameter("NomeDaFoto", FotoName)
            .addBodyParameter(FileBody(File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString()
                    + File.separator
                    + "Today"
                    + File.separator
                    + "Today_20181116155706.jpg")))
            .setPriority(Priority.HIGH)
            .build()
            .getAsOkHttpResponse(object : OkHttpResponseListener {
                override fun onResponse(response: Response?) {
                    if (response != null) {
                        if (response.isSuccessful) {

                            toast(response.toString())
                        }
                        toast(response.toString())
                    }
                    toast(response.toString())

                }
                override fun onError(anError: ANError?) {
                    toast(anError.toString())
                }

            })
}

Upvotes: 1

Views: 425

Answers (0)

Related Questions