@capgo/capacitor-uploader 0.0.6 → 0.0.9

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.
@@ -10,7 +10,7 @@ import net.gotev.uploadservice.UploadServiceConfig;
10
10
  import net.gotev.uploadservice.data.UploadNotificationConfig;
11
11
  import net.gotev.uploadservice.data.UploadNotificationStatusConfig;
12
12
  import net.gotev.uploadservice.observer.request.RequestObserverDelegate;
13
- import net.gotev.uploadservice.protocols.multipart.MultipartUploadRequest;
13
+ import net.gotev.uploadservice.protocols.binary.BinaryUploadRequest;
14
14
 
15
15
  public class Uploader {
16
16
 
@@ -60,15 +60,15 @@ public class Uploader {
60
60
  notificationTitle
61
61
  );
62
62
 
63
- MultipartUploadRequest request = new MultipartUploadRequest(
64
- context,
65
- serverUrl
66
- )
63
+ BinaryUploadRequest request = new BinaryUploadRequest(context, serverUrl)
67
64
  .setMethod(httpMethod)
68
- .addFileToUpload(filePath, "file", mimeType) // Updated this line
65
+ .setFileToUpload(filePath)
69
66
  .setNotificationConfig((ctx, uploadId) -> notificationConfig)
70
67
  .setMaxRetries(maxRetries);
71
68
 
69
+ // Set the Content-Type header for the file
70
+ request.addHeader("Content-Type", mimeType);
71
+
72
72
  // Add headers
73
73
  for (Map.Entry<String, String> entry : headers.entrySet()) {
74
74
  request.addHeader(entry.getKey(), entry.getValue());
@@ -1,6 +1,9 @@
1
1
  package ee.forgr.capacitor.uploader;
2
2
 
3
+ import android.app.NotificationChannel;
4
+ import android.app.NotificationManager;
3
5
  import android.content.Context;
6
+ import android.os.Build;
4
7
  import com.getcapacitor.JSObject;
5
8
  import com.getcapacitor.Plugin;
6
9
  import com.getcapacitor.PluginCall;
@@ -18,8 +21,32 @@ public class UploaderPlugin extends Plugin {
18
21
 
19
22
  private Uploader implementation;
20
23
 
24
+ private static final String CHANNEL_ID =
25
+ "ee.forgr.capacitor.uploader.notification_channel_id";
26
+ private static final String CHANNEL_NAME = "Uploader Notifications";
27
+ private static final String CHANNEL_DESCRIPTION =
28
+ "Notifications for file uploads";
29
+
30
+ private void createNotificationChannel() {
31
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
32
+ NotificationManager notificationManager =
33
+ (NotificationManager) getContext()
34
+ .getSystemService(Context.NOTIFICATION_SERVICE);
35
+
36
+ NotificationChannel channel = new NotificationChannel(
37
+ CHANNEL_ID,
38
+ CHANNEL_NAME,
39
+ NotificationManager.IMPORTANCE_DEFAULT
40
+ );
41
+ channel.setDescription(CHANNEL_DESCRIPTION);
42
+
43
+ notificationManager.createNotificationChannel(channel);
44
+ }
45
+ }
46
+
21
47
  @Override
22
48
  public void load() {
49
+ createNotificationChannel();
23
50
  implementation = new Uploader(
24
51
  getContext(),
25
52
  new RequestObserverDelegate() {
@@ -27,7 +27,9 @@ import MobileCoreServices
27
27
  request.setValue(value, forHTTPHeaderField: key)
28
28
  }
29
29
 
30
- let fileUrl = URL(fileURLWithPath: filePath)
30
+ guard let fileUrl = URL(string: filePath) else {
31
+ throw NSError(domain: "UploaderPlugin", code: 1, userInfo: [NSLocalizedDescriptionKey: "Invalid file URL"])
32
+ }
31
33
  let mimeType = options["mimeType"] as? String ?? guessMIMEType(from: filePath)
32
34
 
33
35
  let task: URLSessionTask
@@ -6,7 +6,7 @@ public class UploaderPlugin: CAPPlugin {
6
6
  private let implementation = Uploader()
7
7
  public let pluginMethods: [CAPPluginMethod] = [
8
8
  CAPPluginMethod(name: "startUpload", returnType: CAPPluginReturnPromise),
9
- CAPPluginMethod(name: "removeUpload", returnType: CAPPluginReturnPromise),
9
+ CAPPluginMethod(name: "removeUpload", returnType: CAPPluginReturnPromise)
10
10
  ]
11
11
 
12
12
  override public func load() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-uploader",
3
- "version": "0.0.6",
3
+ "version": "0.0.9",
4
4
  "description": "Upload file natively",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",