social_share_plugin icon indicating copy to clipboard operation
social_share_plugin copied to clipboard

How do I share an image URL link instead of the file path to Instagram?

Open VikasPawar2112 opened this issue 4 years ago • 5 comments

VikasPawar2112 avatar May 18 '20 07:05 VikasPawar2112

+1 on that!

ThomasJaeger avatar May 31 '20 17:05 ThomasJaeger

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)

noelmathewisaac avatar Jul 11 '20 16:07 noelmathewisaac

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!

kaarens93 avatar Aug 07 '20 07:08 kaarens93

Same problem here

Ruhasi avatar Apr 01 '23 10:04 Ruhasi

@noelmathewisaac It works! Thx

leleging avatar Aug 19 '24 02:08 leleging