【发布时间】:2022-08-18 02:00:36
【问题描述】:
我是新迁移到颤振最新版本。我一直在将 Flutter v1 迁移到 v3,但是当我使用插件 file_picker: ^5.0.1 画廊和相机工作正常,但每当是文件时,就会出现此错误,我一直在到处搜索,但我没有找到了解决方案,有谁知道我该如何解决这个问题?
var request = http.MultipartRequest(\'POST\', Uri.parse(baseURL! + urlFiles));
request.fields[\'apiKey\'] = API_KEY;
request.fields[\'username\'] = username as String;
request.fields[\'authenticationCode\'] = authCode as String;
request.files.add(await http.MultipartFile.fromPath(\'myfile\', filename)); //<-- Error
var streamedResponse = await request.send();
final response = await http.Response.fromStream(streamedResponse);
// If the response from the server is correct code == 200 we proceed with the parsing of the json
if (response.statusCode == 200) {
final responseJson = json.decode(response.body);
这就是我处理文件和图像的方式:
_pickFile() async {
FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result == null) return;
PlatformFile file = result.files.first;
print(\'File Name: ${file.name}\');
print(\'File Size: ${file.size}\');
print(\'File Extension: ${file.extension}\');
print(\'File Path: ${file.path}\');
// if (path == null) return;
Navigator.pop(context);
_uploadFile(\'$path\');}
_getPhoto(ImageSource source) async {
var image = await ImagePicker().getImage(source: source, imageQuality: 50);
if (image == null) return;
path = image.path;
Navigator.pop(context);
if (kDebugMode) {
print(\'---> ImagePicker $path\');
}
_uploadFile(path as String);}
标签: android ios flutter filepicker.io