Created
February 21, 2017 05:32
-
-
Save landlight/fba5f3be3ad8c544e4518a0392277a76 to your computer and use it in GitHub Desktop.
Video Upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface SmileVideoAPI { | |
@GET("video/1") | |
Call<VideoUrl> getPath(); | |
@Multipart | |
@POST("video/upload") | |
Call<ResponseBody> uploadVideo(@Part("description") RequestBody description, @Part MultipartBody.Part video); | |
} | |
private String uploadVideoToServer(String pathToVideoFile) { | |
Log.v("test_get", "get the file"); | |
Retrofit retrofit = new Retrofit.Builder() | |
.baseUrl("http://xxxx:xxx/") | |
.addConverterFactory(GsonConverterFactory.create()) | |
.build(); | |
SmileVideoAPI service = retrofit.create(SmileVideoAPI.class); | |
MediaType MEDIA_TYPE = MediaType.parse("multipart/form-data"); | |
File videoFile = new File(pathToVideoFile); | |
RequestBody videoBody = RequestBody.create(MEDIA_TYPE, videoFile); | |
MultipartBody.Part vFile = MultipartBody.Part.createFormData("file", videoFile.getName(), videoBody); | |
RequestBody description = createPartFromString("desc"); | |
Log.v("test_get", "before uploading"); | |
Call<ResponseBody> call = service.uploadVideo(description, vFile); | |
Log.v("test_get", "after uploading"); | |
call.enqueue(new Callback<ResponseBody>(){ | |
@Override | |
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) { | |
if (response.isSuccessful()) | |
{ | |
Log.i("mok","S"); | |
ResponseBody rb = response.body(); | |
Log.i("mok",rb.toString()); | |
} | |
else { | |
Log.i("mok", "F"); | |
ResponseBody rb = response.errorBody(); | |
Log.i("mok", rb.toString()); | |
} | |
} | |
@Override | |
public void onFailure(Call<ResponseBody> call, Throwable t) { | |
t.printStackTrace(); | |
Log.i("mok",t.getCause()+""); | |
Log.i("mok","T"); | |
finish(); | |
} | |
}); | |
return msg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment