public static String upload(String url, File file) throws IOException {
OkHttpClient client = new OkHttpClient();
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("imgfilename", file.getName(),
RequestBody.create(MediaType.parse("multipart/form-data"), file))
.build();
Request request = new Request.Builder()
.url(url)
.post(requestBody)
.build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
} else {
return response.body().string();
}
}
06-12
3292
06-12
1176