无法打开文件,路径=“文件:///路径”(OS错误:没有这样的文件或目录,错误号= 2)
你好我试图缩小图像尺寸使用图像库 从画廊挑选,而试图,我这样无法打开文件,路径=“文件:///路径”(OS错误:没有这样的文件或目录,错误号= 2)
E/flutter (13796): [ERROR:lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (13796): FileSystemException: Cannot open file, path = 'file:///storage/emulated/0/WhatsApp/Media/WhatsApp%20Images/IMG-20171016-WA0020.jpg' (OS Error: No such file or directory, errno = 2)
E/flutter (13796): #0 _File.throwIfError (file_impl.dart:618)
E/flutter (13796): #1 _File.openSync (file_impl.dart:473)
E/flutter (13796): #2 _File.readAsBytesSync (file_impl.dart:533)
E/flutter (13796): #3 _AddNewUserState.qqq (/data/data/com.prayuta.chitfunds/cache/chitfundsUNFPRG/chitfunds/lib/users.dart:420:97)
E/flutter (13796): <asynchronous suspension>
E/flutter (13796): #4 _AddNewUserState.build.<anonymous closure> (/data/data/com.prayuta.chitfunds/cache/chitfundsUNFPRG/chitfunds/lib/users.dart:686:19)
E/flutter (13796): #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
E/flutter (13796): #6 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:149:9)
E/flutter (13796): #7 TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:119:7)
E/flutter (13796): #8 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter (13796): #9 BindingBase&SchedulerBinding&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:147:20)
E/flutter (13796): #10 BindingBase&SchedulerBinding&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
E/flutter (13796): #11 BindingBase&SchedulerBinding&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
E/flutter (13796): #12 BindingBase&SchedulerBinding&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
E/flutter (13796): #13 BindingBase&SchedulerBinding&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
E/flutter (13796): #14 _invoke1 (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:100)
E/flutter (13796): #15 _dispatchPointerDataPacket (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:58)
面临的错误任何一个可以帮助我的代码看起来像这样
import 'package:image/image.dart' as convertinglib;
File imageFile = await ImagePicker.pickImage();
convertinglib.Image image = convertinglib.decodeImage(new Io.File(imageFile.uri.toString()).readAsBytesSync());
convertinglib.Image thumbnail = convertinglib.copyResize(image, 120);
的问题不是在读取文件图片选择器或转换为更小的尺寸,但与将文件写入文件系统。我拿它,你拿了dart image package 的示例代码,它在调整文件大小后将文件写入文件系统。这种形式在智能手机上不可能实现。
您发布实际上并没有造成错误,但该行做的代码:
new Io.File(imageFile.uri.toString())
..writeAsBytesSync(convertingLib.encodePng(thumbnail))
这样做的问题是,imagePicker隐藏图像的实际URI。它为您提供了一条如下所示的路径:.../tmp/image_picker_1547A964-791E-426F-A682-33D3AFA995BA-18295-0003861F9255294A.jpg
不能用于保存您的新缩略图。
您可以尝试避免将文件保存在第一位或将其保存到实际存在的位置(例如,您可以使用path_provider plugin作为此目的)。
那么如何解决它,或U可以说是有任何其他方式 –
编辑我的回答 –
但我想返回的文件如何得到它 –
我想这个问题是通过图像URI作为一个字符串。 有一个fromUri
构造函数,您可以在其中传递文件URI。
使用try
new Io.File.fromUri(imageFile.uri)
代替
new Io.File(imageFile.uri.toString())
的问题是,在image_picker隐藏应用程序真实的URL。查看我的答案获取更多信息。 –
但我想要返回类型作为文件来上传Firebase存储 –
是什么包:图像/ image.dart是什么样子?图像选择器似乎工作正常。 –
你能发布一个工作班的最小例子,它会产生错误吗? –
imageuploader()async {fileImageFile = await ImagePicker.pickImage(); convertinglib.Image图像= convertinglib.decodeImage(新Io.File(imageFile.uri.toString())readAsBytesSync()); conversionlib.Image thumbnail = convertinglib.copyResize(image,120); DateTime now = new DateTime.now(); var datestamp = new DateFormat(“yyyyMMdd'T'HHmmss”); String currentdate = datestamp.format(now); 的setState((){ progressBarStatus = TRUE; }); –