Skip to content

Commit

Permalink
fix: copyTo on android to put the file in a uniquely named dir (#397)
Browse files Browse the repository at this point in the history
* When using copyTo on android put the file in a uniquely named directory

* Update package.json

Co-authored-by: Vojtech Novak <[email protected]>
  • Loading branch information
tamslinn and vonovak authored Mar 15, 2021
1 parent f2cd790 commit f79be55
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
* @see <a href="https://developer.android.com/guide/topics/providers/document-provider.html">android documentation</a>
Expand Down Expand Up @@ -239,6 +240,9 @@ private void prepareFileUri(Context context, WritableMap map, Uri uri) {
if (copyTo.equals("documentDirectory")) {
dir = context.getFilesDir();
}
// we don't want to rename the file so we put it into a unique location
dir = new File(dir, UUID.randomUUID().toString());
dir.mkdir();
String fileName = map.getString(FIELD_NAME);
if (fileName == null) {
fileName = String.valueOf(System.currentTimeMillis());
Expand Down

0 comments on commit f79be55

Please sign in to comment.