I am trying to upload a video to a server using okhttp client and although the onsuccess method is reached the video is not playable on the website. My question is, am I uploading the video correctly using the storage path or am I missing something?
public void videoUploadTo(String url, String storageUrl) {
OkHttpClient client = new OkHttpClient();
File videoFile = new File(storageUrl);
Uri videoUri = Uri.fromFile(videoFile);
String content_type = getMimeType(videoFile.getPath());
RequestBody fileBody = RequestBody.create(MediaType.parse(content_type), videoFile);
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("type", content_type)
.addFormDataPart("uploaded_video", storageUrl.substring(storageUrl.lastIndexOf("/") + 1), fileBody)
.build();
Request request = new Request.Builder()
.url(siteUrl + url)
.put(requestBody)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.d("onfailure video", e.getMessage());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Log.d("onResponse video", response.message());
}
});
}