Skip to content

Copy attachments as temporary files before sending#6

Open
adamski wants to merge 17 commits intomasterfrom
temp-file-attachments
Open

Copy attachments as temporary files before sending#6
adamski wants to merge 17 commits intomasterfrom
temp-file-attachments

Conversation

@adamski
Copy link
Owner

@adamski adamski commented May 15, 2018

This was necessary in my case as the files were local to the app. May not be necessary in other cases, in which case a boolean switch should be added.

@adamski
Copy link
Owner Author

adamski commented May 15, 2018

@timscott your input on this PR would be useful.

copy (file, temporaryFile);
} catch (IOException e) {
e.printStackTrace();
Log.e("RNMail", "Error copying to temporary file");
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably fail here as temporaryFile will be null

@timscott
Copy link

I guess you are solving the problem that the mail program will not have permission to the original file if it's an app asset?

I have solved that in my use case, by using react-native-fs to copy asset files once to RNFS.ExternalDirectoryPath. I would rather not copy several files each time the user attaches.

However, I agree that it would be good to handle this case in a built-in way, and copying to a temp file seems fine. Some questions:

  1. What if the file is already in a location that is accessible to the mail program? It would be better not to copy it. You mentioned a switch, but can't the code detect if it's in an accessible location?
  2. I didn't see where the temp file is cleaned up. Maybe that's not possible since you don't know when the mail app is done with it.
  3. When you create the temp file, does that overwrite any existing file with the same path? Bad if not, I guess.

@adamski
Copy link
Owner Author

adamski commented May 16, 2018

Thanks for those points. I had a look and found some documentation which looks like this issue could be avoided by using the FileProvider: https://developer.android.com/training/secure-file-sharing/share-file

@timscott
Copy link

Cool, it would be great if you could get that working. It would allow me to delete some code from my app. My favorite coding is deleting code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants