Android Kotlin Volley 同时上传图片和 post 其他值?
Android Kotlin Volley upload image and post other values at the same time?
我正在使用本教程中的代码
Upload an Image or File to Your Server Using Volley in Kotlin
代码有效 我可以上传图片,但我还需要 post 其他值连同同一请求中的图片。
以下是执行上传的代码。如何将其他 post 值添加到请求中?
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)
}
@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;
}
我正在使用本教程中的代码 Upload an Image or File to Your Server Using Volley in Kotlin
代码有效 我可以上传图片,但我还需要 post 其他值连同同一请求中的图片。 以下是执行上传的代码。如何将其他 post 值添加到请求中?
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)
}
@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;
}