Come faccio a monitorare il progresso di caricamento in OkHttp 3 posso trovare risposte per v2, ma non v3, come thisOKHTTP 3 Monitoraggio Multipart caricare il progresso
Una richiesta Multipart campione ricette OkHttp
private static final String IMGUR_CLIENT_ID = "...";
private static final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");
private final OkHttpClient client = new OkHttpClient();
public void run() throws Exception {
// Use the imgur image upload API as documented at https://api.imgur.com/endpoints/image
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("title", "Square Logo")
.addFormDataPart("image", "logo-square.png",
RequestBody.create(MEDIA_TYPE_PNG, new File("website/static/logo-square.png")))
.build();
Request request = new Request.Builder()
.header("Authorization", "Client-ID " + IMGUR_CLIENT_ID)
.url("https://api.imgur.com/3/image")
.post(requestBody)
.build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
System.out.println(response.body().string());
}
C'è una ricetta nei campioni 'OkHttp3'. Mostra come mostrare lo stato di avanzamento di un download. Se lo guardi, potresti essere in grado di creare un monitor per il progresso del caricamento. Trovalo qui https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/Progress.java –