From 70716a0a89b7cda1e20bfafec1a5d69862394367 Mon Sep 17 00:00:00 2001 From: Sk Heerah Zafir Date: Mon, 28 Mar 2022 13:52:17 +0400 Subject: [PATCH 1/8] Version okHttp and newCachedThreadPool() --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 3e17574c..168caf38 100644 --- a/plugin.xml +++ b/plugin.xml @@ -16,7 +16,7 @@ - + From 78d50047daa1aa855ed5c52c1faa7a8ae947418e Mon Sep 17 00:00:00 2001 From: Sk Heerah Zafir Date: Mon, 28 Mar 2022 13:52:25 +0400 Subject: [PATCH 2/8] newCachedThreadPool() --- src/android/FileTransferBackground.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/FileTransferBackground.java b/src/android/FileTransferBackground.java index 34a5932f..d671fd7f 100644 --- a/src/android/FileTransferBackground.java +++ b/src/android/FileTransferBackground.java @@ -122,7 +122,7 @@ private void sendError(final String id, final String reason, boolean userCancele @Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) { if(executorService == null) { - executorService = Executors.newScheduledThreadPool(4); + executorService = Executors.newCachedThreadPool(); } executorService.schedule(() -> { From 739c665ea314f39f3e82378a965405f89916405c Mon Sep 17 00:00:00 2001 From: Sk Heerah Zafir Date: Mon, 28 Mar 2022 14:02:02 +0400 Subject: [PATCH 3/8] rm newCachedThreadPool() --- src/android/FileTransferBackground.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/FileTransferBackground.java b/src/android/FileTransferBackground.java index d671fd7f..34a5932f 100644 --- a/src/android/FileTransferBackground.java +++ b/src/android/FileTransferBackground.java @@ -122,7 +122,7 @@ private void sendError(final String id, final String reason, boolean userCancele @Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) { if(executorService == null) { - executorService = Executors.newCachedThreadPool(); + executorService = Executors.newScheduledThreadPool(4); } executorService.schedule(() -> { From 17353d61b501e1479a991df353b0484b20de5709 Mon Sep 17 00:00:00 2001 From: Sk Heerah Zafir Date: Mon, 28 Mar 2022 16:53:57 +0400 Subject: [PATCH 4/8] ; charset=utf-8 --- plugin.xml | 2 +- src/android/UploadTask.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.xml b/plugin.xml index 168caf38..a3a1ba30 100644 --- a/plugin.xml +++ b/plugin.xml @@ -16,7 +16,7 @@ - + diff --git a/src/android/UploadTask.java b/src/android/UploadTask.java index 103f8eb7..0435e67a 100644 --- a/src/android/UploadTask.java +++ b/src/android/UploadTask.java @@ -328,7 +328,7 @@ private Request createRequest() throws FileNotFoundException { // Build file reader String extension = MimeTypeMap.getFileExtensionFromUrl(filepath); - MediaType mediaType = MediaType.parse(MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)); + MediaType mediaType = MediaType.parse(MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) + "; charset=utf-8"); File file = new File(filepath); ProgressRequestBody fileRequestBody = new ProgressRequestBody(mediaType, file.length(), new FileInputStream(file), this::handleProgress); From fe2c89fd7b818994f31a1dee247f7d1128a61fac Mon Sep 17 00:00:00 2001 From: Sk Heerah Zafir Date: Mon, 28 Mar 2022 18:11:05 +0400 Subject: [PATCH 5/8] IF application/json --- src/android/UploadTask.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/android/UploadTask.java b/src/android/UploadTask.java index 0435e67a..a9f9c6be 100644 --- a/src/android/UploadTask.java +++ b/src/android/UploadTask.java @@ -328,7 +328,12 @@ private Request createRequest() throws FileNotFoundException { // Build file reader String extension = MimeTypeMap.getFileExtensionFromUrl(filepath); - MediaType mediaType = MediaType.parse(MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) + "; charset=utf-8"); + MediaType mediaType; + if (MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) == "application/json") { + mediaType = MediaType.parse(MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) + "; charset=utf-8"); + } else { + mediaType = MediaType.parse(MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)); + } File file = new File(filepath); ProgressRequestBody fileRequestBody = new ProgressRequestBody(mediaType, file.length(), new FileInputStream(file), this::handleProgress); From c1222813b59b7711cc5ed41a7d5dc658519e353c Mon Sep 17 00:00:00 2001 From: Sk Heerah Zafir Date: Mon, 28 Mar 2022 18:28:24 +0400 Subject: [PATCH 6/8] /json or text/ --- src/android/UploadTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/UploadTask.java b/src/android/UploadTask.java index a9f9c6be..e0fed854 100644 --- a/src/android/UploadTask.java +++ b/src/android/UploadTask.java @@ -329,7 +329,7 @@ private Request createRequest() throws FileNotFoundException { // Build file reader String extension = MimeTypeMap.getFileExtensionFromUrl(filepath); MediaType mediaType; - if (MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) == "application/json") { + if (MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension).endsWith("/json") || MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension).startsWith("text/")) { mediaType = MediaType.parse(MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) + "; charset=utf-8"); } else { mediaType = MediaType.parse(MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)); From 7c21b555cfa205b8631fe749f4127bd4b6807e53 Mon Sep 17 00:00:00 2001 From: Sk Heerah Zafir Date: Tue, 29 Mar 2022 12:11:05 +0400 Subject: [PATCH 7/8] extension.equals("json") --- src/android/UploadTask.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/android/UploadTask.java b/src/android/UploadTask.java index e0fed854..1c69e6b1 100644 --- a/src/android/UploadTask.java +++ b/src/android/UploadTask.java @@ -329,7 +329,9 @@ private Request createRequest() throws FileNotFoundException { // Build file reader String extension = MimeTypeMap.getFileExtensionFromUrl(filepath); MediaType mediaType; - if (MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension).endsWith("/json") || MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension).startsWith("text/")) { + if (extension.equals("json")) { + // Does not on Devices less than Android 10 (Stop Execution) + // https://stackoverflow.com/questions/44667125/getmimetypefromextension-returns-null-when-i-pass-json-as-extension mediaType = MediaType.parse(MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) + "; charset=utf-8"); } else { mediaType = MediaType.parse(MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)); From f72e9f0f1534863bec99f3667df7b068b116b602 Mon Sep 17 00:00:00 2001 From: Sk Heerah Zafir Date: Tue, 29 Mar 2022 12:14:29 +0400 Subject: [PATCH 8/8] Comment --- src/android/UploadTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/UploadTask.java b/src/android/UploadTask.java index 1c69e6b1..038fad67 100644 --- a/src/android/UploadTask.java +++ b/src/android/UploadTask.java @@ -330,7 +330,7 @@ private Request createRequest() throws FileNotFoundException { String extension = MimeTypeMap.getFileExtensionFromUrl(filepath); MediaType mediaType; if (extension.equals("json")) { - // Does not on Devices less than Android 10 (Stop Execution) + // Does not support devices less than Android 10 (Stop Execution) // https://stackoverflow.com/questions/44667125/getmimetypefromextension-returns-null-when-i-pass-json-as-extension mediaType = MediaType.parse(MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) + "; charset=utf-8"); } else {