romatroskin / social_share_plugin

Social Share to Facebook and Instagram Flutter plugin.
BSD 2-Clause "Simplified" License
41 stars 87 forks source link

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

Open VikasPawar2112 opened 4 years ago

ThomasJaeger commented 4 years ago

+1 on that!

noelmathewisaac commented 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)

kaarens93 commented 4 years ago

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!

Ruhasi commented 1 year ago

Same problem here

leleging commented 2 months ago

@noelmathewisaac It works! Thx