Open VikasPawar2112 opened 4 years ago
I used this workaround for converting a URL to file before sharing the file path.
import 'package:http/http.dart' as http;
import 'package:path_provider/path_provider.dart';
import 'dart:io';
import 'dart:math';
Future<File> urlToFile(String imageUrl) async {
// generate random number.
var rng = new Random();
// get temporary directory of device.
Directory tempDir = await getTemporaryDirectory();
// get temporary path from temporary directory.
String tempPath = tempDir.path;
// create a new file in temporary path with random file name.
File file = new File('$tempPath'+ '/' + (rng.nextInt(100)).toString() +'.png');
// call http.get method and pass imageUrl into it to get response.
http.Response response = await http.get(imageUrl);
// write bodyBytes received in response to file.
await file.writeAsBytes(response.bodyBytes);
// now return the file which is created with random name in
// temporary directory and image bytes from response is written to // that file.
return file;
}
(Reference: https://medium.com/@mrgulshanyadav/convert-image-url-to-file-format-in-flutter-10421bccfd18)
hi @noelmathewisaac i followed along but I got a PlatformException (failed to find configured root that contains /data/data....) do you know what the problem might be? something might be wrong with my path xml file but I'm not sure what it should look like. thank you!
Same problem here
@noelmathewisaac It works! Thx
+1 on that!