I receive the image by an implicit intent from the gallery and while I install it in ImageView (bitmap). You need to send JSON with fields to the server, one of which is a link to the image. I use Retrofit2. I read something about a separate image download. There are thoughts on this. Send an image to the server (the user should play ProgressBar), get the path to the location on the server in response, and with this result send the final JSON Something is already returned to the server.

"results": [{ "id": 1, "title": "YOUR TITLE 1", "type": "YOUR TYPE 1", "picture": "http://myhost.ru/media/%D00%A3.jpg" }] 

 val file = File(path.path) val requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file) val body = MultipartBody.Part.createFormData("picture", file.name, requestFile) 

 @Multipart @POST("endpoint/") fun uploadPicture(@Part picture: MultipartBody.Part): Single<Any?> 
  • As I understand it, the question is: how to send JSON to the server using Retrofit2? - George Chebotaryov
  • @ GeorgiyChebotarev how to send an image to a server together with other fields. - nuqss pm
  • The problem is not formulated, because everything is painted in the question, and everything is correct: send the file, add the path to json, send json. In such a sequence. - Eugene Krivenja pm

0