我想制作一个将视频发送到网站http://comixify.ai的应用 在这个网站上,视频被翻译成漫画。 我确实压缩了视频,但是无法发送视频。
API
Request:
Path: http://comixify.ai/comixify/
Method: POST
Data:
{
file: video/*
}
* Max size of video is 100 MB, max length of the video is 25 minutes.
Response:
{
status: string,
comic: string
}
comic - url to result comics
我使用Retrofit 2库发送视频。
我在向您的服务器供水时遇到问题,也许我使用的API不正确? 请帮助。
错误消息:超时
public class MainActivity extends AppCompatActivity {
private static final String baseURL = "http://comixify.ai";
private void uploadVideoToServer(String pathToVideoFile){
File videoFile = new File(pathToVideoFile);
RequestBody videoBody = RequestBody.create(MediaType.parse("video/*"), videoFile);
MultipartBody.Part vFile = MultipartBody.Part.createFormData("video", videoFile.getName(), videoBody);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseURL)
.addConverterFactory(GsonConverterFactory.create())
.build();
VideoInterface vInterface = retrofit.create(VideoInterface.class);
Call<ResultObject> serverCom = vInterface.uploadVideoToServer(vFile);
serverCom.enqueue(new Callback<ResultObject>() {
@Override
public void onResponse(Call<ResultObject> call, Response<ResultObject> response) {
try {
ResultObject result = response.body();
if (!TextUtils.isEmpty(result.getStatus())){
Toast.makeText(MainActivity.this, "Status " + result.getStatus(), Toast.LENGTH_LONG).show();
Log.d(TAG, "Status " + result.getStatus());
}
else if(!TextUtils.isEmpty(result.getComic())){
Toast.makeText(MainActivity.this, "Comic " + result.getComic(), Toast.LENGTH_LONG).show();
Log.d(TAG, "Comic " + result.getComic());
}
}
catch (Exception e){
Toast.makeText(MainActivity.this, "Нет данных", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<ResultObject> call, Throwable t) {
Log.d(TAG, "Error message: " + t.getMessage());
}
});
}
}
public interface VideoInterface {
@Multipart
@POST("/comixify/")
Call<ResultObject> uploadVideoToServer(@Part MultipartBody.Part video);
}
public class ResultObject {
@SerializedName("status")
@Expose
private String status;
@SerializedName("comic")
@Expose
private String comic;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getComic() {
return comic;
}
public void setComic(String comic) {
this.comic = comic;
}
}