Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot open file, path = 'file:///path' (OS Error: No such file or directory, errno = 2)

Tags:

flutter

dart

Hi I am trying reduce image size picked from gallery using image library while trying that I am facing error like this

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)

can any one help and my code look like this

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);
like image 397
siva kumar Avatar asked Oct 17 '17 04:10

siva kumar


1 Answers

I suppose the issue is passing the Image URI as a String. There is a fromUri constructor where you can pass the file URI.

Try using

    new Io.File.fromUri(imageFile.uri)

instead of

    new Io.File(imageFile.uri.toString())
like image 85
Hemanth Raj Avatar answered Oct 21 '22 05:10

Hemanth Raj