Android Kotlin Volley上传图像并同时发布其他值?

问题描述 投票:0回答:1

我正在使用本教程中的代码Upload an Image or File to Your Server Using Volley in Kotlin

该代码有效,我可以上传图像,但我还需要在同一请求中将其他值与图像一起发布。以下是执行上传的代码。如何将其他帖子值添加到请求中?

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)
}
android post kotlin android-volley image-uploading
1个回答
1
投票
            @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;
            }
© www.soinside.com 2019 - 2024. All rights reserved.