MultipartRequest 成功上传到s3,但数据似乎无效
MultipartRequest uploads successfully to s3, but data appears to be invalid
在 Flutter 中,这似乎是一个非常简单的过程。但是当我下载我上传到 s3 的视频时,我无法播放视频。视频播放器告诉我数据已损坏。
uploadUri 是预签名的 s3 link。 filePath 是我视频的正确路径。
我从发送中收到 200 响应。
Future<void> postVideo( String filePath, String uploadUri ) async {
var request = http.MultipartRequest('PUT', Uri.parse( uploadUri ) );
request.files.add(
await http.MultipartFile.fromPath(
'video',
filePath,
contentType: MediaType('video','mp4')
));
final response = await request.send();
if (response.statusCode == 201 || response.statusCode == 200 ) {
print( 'submit video response: ' + response.toString() );
} else {
throw Exception('Failed to post video');
}
}
有什么想法吗?
这是有效的方法,不确定是什么魔法..
Future<void> postVideo( String filePath, String uploadUri ) async {
File file = File(filePath);
List<int> imageData = file.readAsBytesSync();
var response = await http.put(uploadUri, body: imageData, headers: {
"Content-Type": "octet-stream",
"Content-Disposition": 'attachment; filename="resource"',
"Content-Encoding": "identity",
"Content-Length": file.lengthSync().toString()
});
if (response.statusCode == 201 || response.statusCode == 200 ) {
print( 'submit video response: ' + response.toString() );
} else {
throw Exception('Failed to post story');
}
}
在 Flutter 中,这似乎是一个非常简单的过程。但是当我下载我上传到 s3 的视频时,我无法播放视频。视频播放器告诉我数据已损坏。 uploadUri 是预签名的 s3 link。 filePath 是我视频的正确路径。 我从发送中收到 200 响应。
Future<void> postVideo( String filePath, String uploadUri ) async {
var request = http.MultipartRequest('PUT', Uri.parse( uploadUri ) );
request.files.add(
await http.MultipartFile.fromPath(
'video',
filePath,
contentType: MediaType('video','mp4')
));
final response = await request.send();
if (response.statusCode == 201 || response.statusCode == 200 ) {
print( 'submit video response: ' + response.toString() );
} else {
throw Exception('Failed to post video');
}
}
有什么想法吗?
这是有效的方法,不确定是什么魔法..
Future<void> postVideo( String filePath, String uploadUri ) async {
File file = File(filePath);
List<int> imageData = file.readAsBytesSync();
var response = await http.put(uploadUri, body: imageData, headers: {
"Content-Type": "octet-stream",
"Content-Disposition": 'attachment; filename="resource"',
"Content-Encoding": "identity",
"Content-Length": file.lengthSync().toString()
});
if (response.statusCode == 201 || response.statusCode == 200 ) {
print( 'submit video response: ' + response.toString() );
} else {
throw Exception('Failed to post story');
}
}