我想上传视频Firebase Storage。我是这样试的。
Future uploadToStorage() async {
try {
final DateTime now = DateTime.now();
final int millSeconds = now.millisecondsSinceEpoch;
final String month = now.month.toString();
final String date = now.day.toString();
final String storageId = (millSeconds.toString() + uid);
final String today = ('$month-$date');
final file = await ImagePicker.pickVideo(source: ImageSource.gallery);
StorageReference ref = FirebaseStorage.instance.ref().child("video").child(today).child(storageId);
StorageUploadTask uploadTask = ref.putFile(file);
Uri downloadUrl = (await uploadTask.future).downloadUrl;
final String url = downloadUrl.toString();
print(url);
} catch (error) {
print(error);
}
}
Run Code Online (Sandbox Code Playgroud)
但问题是我上传了 3 个不同的视频。一个来自真实设备,其他来自 Ios 模拟器,只有一个来自模拟器的视频被识别为这样的视频。
文件:/Users/Daibaku/Library/Developer/CoreSimulator/Devices/C99406E4-12F3-480A-82A6-F6144ADD21AB/data/Containers/Data/Application/23E82E18-9293-4EEB-AEEA-6A7BB773F2F2-6A7BB773F2F2-6A7BB773F2F2-12F3-480A-82A6-F6144ADD21AB …
我正在尝试使用发布请求将视频文件上传到我的服务器。
var file = new File(videoPath);
var uri = Uri.parse(tokenizedUri);
HttpClientRequest request = await new HttpClient().postUrl(uri);
await request.addStream(file.openRead());
var response = await request.close();
response.transform(utf8.decoder).forEach((string) {
print(string); // handle data
});
Run Code Online (Sandbox Code Playgroud)
但是服务器没有得到它。为什么?