react-native-my-uploader-android 1.0.52 → 1.0.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -82,46 +82,47 @@ class MyUploaderModule(private val reactContext: ReactApplicationContext) :
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
try {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
val activity = currentActivity
|
|
86
|
+
?: throw IllegalStateException("Activity is null")
|
|
87
|
+
|
|
88
|
+
val intent: Intent = if (isGallery) {
|
|
89
|
+
// ✅ TÜM ANDROID SÜRÜMLERİNDE ÇALIŞAN GALERİ
|
|
90
|
+
Intent(Intent.ACTION_GET_CONTENT).apply {
|
|
91
|
+
type = "image/*"
|
|
92
|
+
addCategory(Intent.CATEGORY_OPENABLE)
|
|
93
|
+
if (multipleFiles) {
|
|
94
|
+
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
|
|
93
95
|
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
// ✅ GENEL DOSYA SEÇİCİ
|
|
99
|
+
val fileTypes = options.takeIf { it.hasKey("fileTypes") }
|
|
100
|
+
?.getArray("fileTypes")
|
|
101
|
+
?.toArrayList()
|
|
102
|
+
?.mapNotNull { it.toString() }
|
|
103
|
+
?: listOf("*/*")
|
|
104
|
+
|
|
105
|
+
Intent(Intent.ACTION_GET_CONTENT).apply {
|
|
106
|
+
type = "*/*"
|
|
107
|
+
addCategory(Intent.CATEGORY_OPENABLE)
|
|
108
|
+
putExtra(Intent.EXTRA_MIME_TYPES, fileTypes.toTypedArray())
|
|
109
|
+
if (multipleFiles) {
|
|
110
|
+
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
|
-
|
|
112
|
-
// ✅ HER ZAMAN CHOOSER → MIUI SAFE
|
|
113
|
-
activity.startActivityForResult(
|
|
114
|
-
Intent.createChooser(intent, "Bir uygulama seçin"),
|
|
115
|
-
REQUEST_CODE
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
} catch (e: Exception) {
|
|
119
|
-
pickerPromise?.reject(
|
|
120
|
-
E_FAILED_TO_OPEN_DOCUMENT,
|
|
121
|
-
e.localizedMessage ?: "Dosya seçici açılamadı."
|
|
122
|
-
)
|
|
123
|
-
pickerPromise = null
|
|
124
113
|
}
|
|
114
|
+
|
|
115
|
+
val chooserIntent = Intent.createChooser(intent, "Bir uygulama seçin")
|
|
116
|
+
activity.startActivityForResult(chooserIntent, REQUEST_CODE)
|
|
117
|
+
|
|
118
|
+
} catch (e: Exception) {
|
|
119
|
+
pickerPromise?.reject(
|
|
120
|
+
E_FAILED_TO_OPEN_DOCUMENT,
|
|
121
|
+
e.localizedMessage ?: "Dosya seçici açılamadı."
|
|
122
|
+
)
|
|
123
|
+
pickerPromise = null
|
|
124
|
+
}
|
|
125
|
+
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
@ReactMethod
|
|
@@ -634,6 +635,32 @@ class MyUploaderModule(private val reactContext: ReactApplicationContext) :
|
|
|
634
635
|
|
|
635
636
|
override fun onNewIntent(intent: Intent) {}
|
|
636
637
|
|
|
638
|
+
private fun copyFileToInternalStorage(uri: Uri, originalFileName: String): String? {
|
|
639
|
+
return try {
|
|
640
|
+
val inputStream = reactContext.contentResolver.openInputStream(uri) ?: return null
|
|
641
|
+
|
|
642
|
+
// Dosya isminin çakışmaması için timestamp ekliyoruz
|
|
643
|
+
val uniqueFileName = "picked_${System.currentTimeMillis()}_$originalFileName"
|
|
644
|
+
val tempFile = File(reactContext.cacheDir, uniqueFileName)
|
|
645
|
+
|
|
646
|
+
val outputStream = FileOutputStream(tempFile)
|
|
647
|
+
|
|
648
|
+
// Stream kopyalama işlemi (Hafıza dostu)
|
|
649
|
+
inputStream.use { input ->
|
|
650
|
+
outputStream.use { output ->
|
|
651
|
+
input.copyTo(output)
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
// file:///... formatında URI döndürür
|
|
656
|
+
Uri.fromFile(tempFile).toString()
|
|
657
|
+
} catch (e: Exception) {
|
|
658
|
+
Log.e("MyUploader", "Kalıcı kopyalama hatası: ${e.message}")
|
|
659
|
+
null
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
|
|
637
664
|
private fun processSelectedFiles(uris: List<Uri>): WritableArray {
|
|
638
665
|
val fileObjects = WritableNativeArray()
|
|
639
666
|
val maxSizeBytes = (maxSize * 1024 * 1024).toLong()
|
|
@@ -669,11 +696,14 @@ class MyUploaderModule(private val reactContext: ReactApplicationContext) :
|
|
|
669
696
|
null
|
|
670
697
|
}
|
|
671
698
|
|
|
699
|
+
val internalFileUri = copyFileToInternalStorage(uri, fileName) ?: uri.toString()
|
|
700
|
+
|
|
701
|
+
|
|
672
702
|
val fileMap = WritableNativeMap().apply {
|
|
673
703
|
putString("fileName", fileName)
|
|
674
704
|
putDouble("fileSize", if (trueSize > 0) trueSize.toDouble() else fileSize.toDouble())
|
|
675
705
|
putString("fileType", mimeType)
|
|
676
|
-
putString("fileUri",
|
|
706
|
+
putString("fileUri", internalFileUri)
|
|
677
707
|
if (withBase64 && base64 != null) {
|
|
678
708
|
putString("base64", base64)
|
|
679
709
|
}
|