Skip to content

Commit f79be55

Browse files
tamslinnvonovak
andauthored
fix: copyTo on android to put the file in a uniquely named dir (#397)
* When using copyTo on android put the file in a uniquely named directory * Update package.json Co-authored-by: Vojtech Novak <vonovak@gmail.com>
1 parent f2cd790 commit f79be55

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

android/src/main/java/io/github/elyx0/reactnativedocumentpicker/DocumentPickerModule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.lang.ref.WeakReference;
3434
import java.util.ArrayList;
3535
import java.util.List;
36+
import java.util.UUID;
3637

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

0 commit comments

Comments
 (0)