@capgo/capacitor-uploader 0.0.11 → 0.0.16

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.
package/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # @capgo/capacitor-uploader
2
- <a href="https://capgo.app/"><img src='https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png' alt='Capgo - Instant updates for capacitor'/></a>
3
- <div align="center">
4
- <h2><a href="https://capgo.app/">Check out: Capgo — Instant updates for capacitor</a></h2>
2
+ <a href="https://capgo.app/"><img src='https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png' alt='Capgo - Instant updates for capacitor'/></a>
3
+
4
+ <div align="center">
5
+ <h2><a href="https://capgo.app/?ref=plugin"> ➡️ Get Instant updates for your App with Capgo 🚀</a></h2>
6
+ <h2><a href="https://capgo.app/consulting/?ref=plugin"> Fix your annoying bug now, Hire a Capacitor expert 💪</a></h2>
5
7
  </div>
6
8
 
7
9
  ## Uploader Plugin
@@ -4,6 +4,7 @@ import android.app.NotificationChannel;
4
4
  import android.app.NotificationManager;
5
5
  import android.content.Context;
6
6
  import android.os.Build;
7
+ import android.webkit.MimeTypeMap;
7
8
  import com.getcapacitor.JSObject;
8
9
  import com.getcapacitor.Plugin;
9
10
  import com.getcapacitor.PluginCall;
@@ -104,6 +105,15 @@ public class UploaderPlugin extends Plugin {
104
105
  );
105
106
  }
106
107
 
108
+ public static String getMimeType(String url) {
109
+ String type = null;
110
+ String extension = MimeTypeMap.getFileExtensionFromUrl(url);
111
+ if (extension != null) {
112
+ type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
113
+ }
114
+ return type;
115
+ }
116
+
107
117
  @PluginMethod
108
118
  public void startUpload(PluginCall call) {
109
119
  String filePath = call.getString("filePath");
@@ -116,12 +126,13 @@ public class UploaderPlugin extends Plugin {
116
126
  "File Upload"
117
127
  );
118
128
  int maxRetries = call.getInt("maxRetries", 2);
119
- String mimeType = call.getString("mimeType"); // Add this line
120
129
 
121
130
  Map<String, String> headers = JSObjectToMap(headersObj);
122
131
  Map<String, String> parameters = JSObjectToMap(parametersObj);
123
132
 
124
133
  try {
134
+ String mimeType = call.getString("mimeType", getMimeType(filePath)); // Add this line
135
+
125
136
  String id = implementation.startUpload(
126
137
  filePath,
127
138
  serverUrl,
@@ -2,12 +2,14 @@ import Foundation
2
2
  import Capacitor
3
3
 
4
4
  @objc(UploaderPlugin)
5
- public class UploaderPlugin: CAPPlugin {
6
- private let implementation = Uploader()
5
+ public class UploaderPlugin: CAPPlugin, CAPBridgedPlugin {
6
+ public let identifier = "UploaderPlugin"
7
+ public let jsName = "Uploader"
7
8
  public let pluginMethods: [CAPPluginMethod] = [
8
9
  CAPPluginMethod(name: "startUpload", returnType: CAPPluginReturnPromise),
9
10
  CAPPluginMethod(name: "removeUpload", returnType: CAPPluginReturnPromise)
10
11
  ]
12
+ private let implementation = Uploader()
11
13
 
12
14
  override public func load() {
13
15
  implementation.eventHandler = { [weak self] event in
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-uploader",
3
- "version": "0.0.11",
3
+ "version": "0.0.16",
4
4
  "description": "Upload file natively",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",