Giter Club home page Giter Club logo

Comments (16)

superandrew213 avatar superandrew213 commented on June 5, 2024

@allthetime. You can't share a base64 image with the current version. You can use my fork in this pr #34.

You have to write your base64 data to a file (you can use react-native-fs for that) then use the share_File option of my fork.

from react-native-share.

allthetime avatar allthetime commented on June 5, 2024

@superandrew213 nice! I just started modifying react-native-send-intent to support images, but if your PR works :) :) thanks

from react-native-share.

allthetime avatar allthetime commented on June 5, 2024

@superandrew213 Have you actually got this working? I have a valid file uri from react-native-fs that can be shared with iOS, but attempting to share it with your PR just gives an empty share, the image is simply not there. I tried taking out the share_text argument and also appending "file:" to the uri, but nothing. Am I missing something?

                        Share.open({
                          share_text: "Share your image!",
                          share_File: file,
                        },(e) => {
                            Alert.alert('error response', e, [{ text: 'close' }])
                        });

from react-native-share.

superandrew213 avatar superandrew213 commented on June 5, 2024

@allthetime yes it should be working. It has to be the absolute url.

Did you use the ExternalDirectoryPath for android? If you store it in the internal storage (DocumentDirectoryPath) it might not work.

from react-native-share.

allthetime avatar allthetime commented on June 5, 2024

@superandrew213 DocumentDirectory is where I'm saving it. do you have an example of an absolute url I can check against?

from react-native-share.

superandrew213 avatar superandrew213 commented on June 5, 2024

@allthetime i think that might be the issue. Try storing it in the ExternalDirectoryPath not DocumentDirectoryPath (for android only).

from react-native-share.

superandrew213 avatar superandrew213 commented on June 5, 2024

I can't get a url right now but paste yours on here

from react-native-share.

allthetime avatar allthetime commented on June 5, 2024

@superandrew213 file:///data/data/com.app/files/image.png

i'll try ExternalDirectoryPath!

from react-native-share.

allthetime avatar allthetime commented on June 5, 2024

@superandrew213

It seems to be getting through but my phone just says "No apps can perform this action"

it's not an error message but dialogue from the Share activity.

Do you by any chance have a working example I can see?

from react-native-share.

allthetime avatar allthetime commented on June 5, 2024

new url is file:///storage/emulated/0/Android/data/com.app/files/img.png

from react-native-share.

allthetime avatar allthetime commented on June 5, 2024

@superandrew213

OOOMMMG..

i was using "share_File"

but you have to use "share_file" (small f)

Thank you for your help!!! It's greatly appreciated.

from react-native-share.

allthetime avatar allthetime commented on June 5, 2024

hmmm, well it loads the share dialogue, but the image is empty... I'm gonna try all the different folders.

from react-native-share.

allthetime avatar allthetime commented on June 5, 2024

@superandrew213

I finally got it working. I don't know if we have an android API missmatch or something, but your library was not reading the file properly (it shows as 0 bytes when I checked the length) and I found a solution by patching stackoverflow answers together. This is a little complicated and doesn't perform super well, but its the only way i could find to make it work (I tried a lot of different methods... Base64 encoding, etc.)

What do you think:


    if (hasValidKey("share_file", options)) {

      try {

        Bitmap bitmap = BitmapFactory.decodeFile(Uri.parse(options.getString("share_file")).getPath());
        String path = MediaStore.Images.Media.insertImage(this.reactContext.getContentResolver(), bitmap, "Image Description", null);

        File file = new File(Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_DOWNLOADS), System.currentTimeMillis() + ".png");
        file.getParentFile().mkdirs();
        FileOutputStream out = new FileOutputStream(file);

        bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
        out.close();

        Uri uri = Uri.fromFile(file);

        intent.putExtra(Intent.EXTRA_STREAM, uri);
        intent.setType("image/png");

      } catch (IOException e) {
          e.printStackTrace();
      }

    }

from react-native-share.

superandrew213 avatar superandrew213 commented on June 5, 2024

@allthetime your code will only allow to share png image files not any file type. See my code below:

if (hasValidKey("share_file", options)) {
      // Create the Uri from the media
      File file = new File(options.getString("share_file"));
      Uri uri = Uri.fromFile(file);
      // Set the MIME type
      String extension = MimeTypeMap.getFileExtensionFromUrl(file.getName());
      String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
      intent.setType(type);
      // Add the Uri to the Intent.
      intent.putExtra(Intent.EXTRA_STREAM, uri);
    }

File file = new File(options.getString("share_file")); this should create the right file. Maybe there is an issue with getting the right MIME type. Try my code again and manually set the mime type intent.setType("image/png");

from react-native-share.

allthetime avatar allthetime commented on June 5, 2024

@superandrew213 Yeah, sorry, I just rushed it out because I'm only using pngs. You'll notice I'm explicitly compressing the bitmap as a png as well right now. I've seen people using image/*, do you know if that works in most cases?

from react-native-share.

superandrew213 avatar superandrew213 commented on June 5, 2024

@allthetime I will have a look and test it again but I'm pretty sure that it works. I think you might not be creating the file properly using react-native-fs. Can you paste your code where you write base64 to file?

image/* will only allow images though.

from react-native-share.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.