Android Kotlin Volley upload image and post other values at the same time?

1.1k Views Asked by At

I am using the code in this tutorial Upload an Image or File to Your Server Using Volley in Kotlin

The code works I can upload an image but I also need to post other values together with the image in the same request. Following is the code which perform the upload. How do I add the other post values to the request?

private fun uploadImage() {
    imageData?: return
    val request = object : VolleyFileUploadRequest(
        Method.POST,
        postURL,
        Response.Listener {
            println("response is: $it")
        },
        Response.ErrorListener {
            println("error is: $it")
        }
    ) {
        override fun getByteData(): MutableMap<String, FileDataPart> {
            var params = HashMap<String, FileDataPart>()
            params["imageFile"] = FileDataPart("image", imageData!!, "jpeg")
            return params
        }
    }
    Volley.newRequestQueue(this).add(request)
}
1

There are 1 best solutions below

1
Manikandan Karuppiyah On BEST ANSWER
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<>();
                params.put("api_token", "gh659gjhvdyudo973823tt9gvjf7i6ric75r76");
                params.put("name", mNameInput.getText().toString());
                params.put("location", mLocationInput.getText().toString());
                params.put("about", mAvatarInput.getText().toString());
                params.put("contact", mContactInput.getText().toString());
                return params;
            }