Comments (16)
@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.
@superandrew213 nice! I just started modifying react-native-send-intent to support images, but if your PR works :) :) thanks
from react-native-share.
@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.
@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.
@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.
@allthetime i think that might be the issue. Try storing it in the ExternalDirectoryPath not DocumentDirectoryPath (for android only).
from react-native-share.
I can't get a url right now but paste yours on here
from react-native-share.
@superandrew213 file:///data/data/com.app/files/image.png
i'll try ExternalDirectoryPath!
from react-native-share.
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.
new url is file:///storage/emulated/0/Android/data/com.app/files/img.png
from react-native-share.
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.
hmmm, well it loads the share dialogue, but the image is empty... I'm gonna try all the different folders.
from react-native-share.
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.
@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.
@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.
@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)
- Support for sharing attachment or text only on email and Slack HOT 3
- App Hang with Termination Error HOT 2
- iOS share instagram story crashes for any iOS version below 17 when using base64 backgroundImage HOT 2
- Messenger Share on iOS not working for me HOT 1
- Share.open options doesn't allow message in IOS HOT 1
- Microsoft Teams HOT 1
- Share.shareSingle is not working in case of Samsung's dual messenger enabled (whatsapp share) HOT 1
- `saveToFiles` ignores `failOnCancel: false` and throws an error [iOS] HOT 1
- Caption for Instagram HOT 1
- How to show a link below the user name on Instagram Stories? HOT 1
- How do I social share post to Instagram with Share.open? HOT 1
- When the share options opened, can i show preview just like how it works in flipkart ? HOT 2
- Facebook stories won't work if the Facebook app is already opened!
- Unable to Share Multiple Files with Different Formats via Whatsapp on IOS
- How can i use this Library in Expo HOT 1
- codegenSpec not being installed HOT 1
- (Android) Share.single with instagram shows image.null text on share screen
- (Android) Share.ShareSingle facebook groups
- How do i share a video on instagram as a post, reel or in instagram chat?
- ShareSingle's result.success immediately resolving as false
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-share.