File file = new File(Environment.getExternalStorageDirectory(), "dd.mp4");
if (!file.exists()) {
Toast.makeText(MainActivity.this, "文件不存在", Toast.LENGTH_SHORT).show();
} else {
RequestBody fileBody = RequestBody.create(MediaType.parse(TYPE), file);
RequestBody requestBody = new MultipartBody.Builder().addFormDataPart("filename", file.getName(), fileBody).build();
Request requestPostFile = new Request.Builder()
.url("http://10.11.64.50/upload/UploadServlet")
.post(requestBody)
.build();
client.newCall(requestPostFile).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, final Response response) throws IOException {
runOnUiThread(new Runnable() {
@Override
public void run() {
tvShow.setText(response.toString());
}
});
}
});
}