我正在尝试使用okhttp客户端将视频上传到服务器,虽然已达到onsuccess方法,但视频无法在网站上播放。 我的问题是,我是使用存储路径正确上传视频还是遗漏了某些内容?
<View style={{flexDirection:'row'}}>
<Text style={styles.style1}>
{text1}
</Text>
<Text style={styles.style2}>
{text2}
</Text>
</View>
答案 0 :(得分:0)
您可以执行以下操作从FileInputStream创建Requestbody:
final InputStream inputStream = new FileInputStream(videoFile);
final long fileSize;
fileSize = videoFile.length();
RequestBody requestBody = new RequestBody() {
@Override
public MediaType contentType() {
return MediaType.parse("video");
}
@Override
public long contentLength() throws IOException {
return fileSize;
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
byte [] buffer = new byte[65536];
int bytesRead = 0;
while ((bytesRead = inputStream.read(buffer)) != -1) {
sink.write(buffer, 0, bytesRead);
}
}
};
然后您可以像这样将主体作为零件添加到MultipartBody中:
.addFormDataPart("video_file", videoFile.getName(), requestBody);