@capgo/capacitor-uploader 0.0.27 → 7.1.1

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.
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
13
  s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '13.0'
14
+ s.ios.deployment_target = '14.0'
15
15
  s.dependency 'Capacitor'
16
16
  s.swift_version = '5.1'
17
17
  end
package/Package.swift CHANGED
@@ -3,14 +3,14 @@ import PackageDescription
3
3
 
4
4
  let package = Package(
5
5
  name: "CapgoCapacitorUploader",
6
- platforms: [.iOS(.v13)],
6
+ platforms: [.iOS(.v14)],
7
7
  products: [
8
8
  .library(
9
9
  name: "CapgoCapacitorUploader",
10
10
  targets: ["UploaderPlugin"])
11
11
  ],
12
12
  dependencies: [
13
- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", branch: "main")
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
14
14
  ],
15
15
  targets: [
16
16
  .target(
package/README.md CHANGED
@@ -252,6 +252,8 @@ addListener(eventName: "events", listenerFunc: (state: UploadEvent) => void) =>
252
252
  | **`mimeType`** | <code>string</code> | | 0.0.1 |
253
253
  | **`parameters`** | <code>{ [key: string]: string; }</code> | | 0.0.1 |
254
254
  | **`maxRetries`** | <code>number</code> | | 0.0.1 |
255
+ | **`uploadType`** | <code>'binary' \| 'multipart'</code> | <code>'binary'</code> | 0.0.2 |
256
+ | **`fileField`** | <code>string</code> | <code>'file'</code> | 0.0.2 |
255
257
 
256
258
 
257
259
  #### PluginListenerHandle
@@ -1,8 +1,8 @@
1
1
  ext {
2
2
  junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
4
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
5
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
6
6
  }
7
7
 
8
8
  buildscript {
@@ -11,7 +11,7 @@ buildscript {
11
11
  mavenCentral()
12
12
  }
13
13
  dependencies {
14
- classpath 'com.android.tools.build:gradle:8.2.1'
14
+ classpath 'com.android.tools.build:gradle:8.7.3'
15
15
  }
16
16
  }
17
17
 
@@ -19,10 +19,10 @@ apply plugin: 'com.android.library'
19
19
 
20
20
  android {
21
21
  namespace "ee.forgr.capacitor.uploader"
22
- compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
22
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
23
23
  defaultConfig {
24
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
25
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
24
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
26
26
  versionCode 1
27
27
  versionName "1.0"
28
28
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -37,8 +37,8 @@ android {
37
37
  abortOnError false
38
38
  }
39
39
  compileOptions {
40
- sourceCompatibility JavaVersion.VERSION_17
41
- targetCompatibility JavaVersion.VERSION_17
40
+ sourceCompatibility JavaVersion.VERSION_21
41
+ targetCompatibility JavaVersion.VERSION_21
42
42
  }
43
43
  }
44
44
 
@@ -52,7 +52,7 @@ dependencies {
52
52
  implementation fileTree(dir: 'libs', include: ['*.jar'])
53
53
  implementation project(':capacitor-android')
54
54
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
- implementation 'net.gotev:uploadservice:4.9.2'
55
+ implementation 'net.gotev:uploadservice:4.9.4'
56
56
  testImplementation "junit:junit:$junitVersion"
57
57
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
58
58
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
@@ -10,6 +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.protocols.binary.BinaryUploadRequest;
13
+ import net.gotev.uploadservice.protocols.multipart.MultipartUploadRequest;
13
14
 
14
15
  public class Uploader {
15
16
 
@@ -51,41 +52,78 @@ public class Uploader {
51
52
  String httpMethod,
52
53
  String notificationTitle,
53
54
  int maxRetries,
54
- String mimeType
55
+ String mimeType,
56
+ String uploadType,
57
+ String fileField
55
58
  ) throws Exception {
56
59
  UploadNotificationConfig notificationConfig = createNotificationConfig(
57
60
  notificationTitle
58
61
  );
59
62
 
63
+ if ("multipart".equals(uploadType)) {
64
+ MultipartUploadRequest request = new MultipartUploadRequest(
65
+ context,
66
+ serverUrl
67
+ )
68
+ .setMethod(httpMethod)
69
+ .setNotificationConfig((ctx, uploadId) -> notificationConfig)
70
+ .setMaxRetries(maxRetries);
71
+
72
+ request.addFileToUpload(
73
+ filePath,
74
+ fileField,
75
+ getFileNameFromUri(Uri.parse(filePath)),
76
+ mimeType
77
+ );
78
+
79
+ for (Map.Entry<String, String> entry : headers.entrySet()) {
80
+ request.addHeader(entry.getKey(), entry.getValue());
81
+ }
82
+ for (Map.Entry<String, String> entry : parameters.entrySet()) {
83
+ request.addParameter(entry.getKey(), entry.getValue());
84
+ }
85
+
86
+ return request.startUpload();
87
+ } else {
88
+ return startBinaryUpload(
89
+ filePath,
90
+ serverUrl,
91
+ headers,
92
+ parameters,
93
+ httpMethod,
94
+ notificationConfig,
95
+ maxRetries,
96
+ mimeType
97
+ );
98
+ }
99
+ }
100
+
101
+ private String startBinaryUpload(
102
+ String filePath,
103
+ String serverUrl,
104
+ Map<String, String> headers,
105
+ Map<String, String> parameters,
106
+ String httpMethod,
107
+ UploadNotificationConfig notificationConfig,
108
+ int maxRetries,
109
+ String mimeType
110
+ ) throws Exception {
60
111
  BinaryUploadRequest request = new BinaryUploadRequest(context, serverUrl)
61
112
  .setMethod(httpMethod)
62
113
  .setFileToUpload(filePath)
63
114
  .setNotificationConfig((ctx, uploadId) -> notificationConfig)
64
115
  .setMaxRetries(maxRetries);
65
116
 
66
- // Set the Content-Type header for the file
67
117
  request.addHeader("Content-Type", mimeType);
68
118
 
69
- // Add headers
70
119
  for (Map.Entry<String, String> entry : headers.entrySet()) {
71
120
  request.addHeader(entry.getKey(), entry.getValue());
72
121
  }
73
122
 
74
- // Add parameters
75
123
  for (Map.Entry<String, String> entry : parameters.entrySet()) {
76
124
  request.addParameter(entry.getKey(), entry.getValue());
77
125
  }
78
126
 
79
- // Set file name if it's a content URI
80
- if (filePath.startsWith("content://")) {
81
- Uri uri = Uri.parse(filePath);
82
- String fileName = getFileNameFromUri(uri);
83
- if (fileName != null) {
84
- request.addParameter("filename", fileName);
85
- }
86
- }
87
-
88
- // Start the upload
89
127
  return request.startUpload();
90
128
  }
91
129
 
@@ -135,12 +135,14 @@ public class UploaderPlugin extends Plugin {
135
135
  "File Upload"
136
136
  );
137
137
  int maxRetries = call.getInt("maxRetries", 2);
138
+ String uploadType = call.getString("uploadType", "binary");
139
+ String fileField = call.getString("fileField", "file");
138
140
 
139
141
  Map<String, String> headers = JSObjectToMap(headersObj);
140
142
  Map<String, String> parameters = JSObjectToMap(parametersObj);
141
143
 
142
144
  try {
143
- String mimeType = call.getString("mimeType", getMimeType(filePath)); // Add this line
145
+ String mimeType = call.getString("mimeType", getMimeType(filePath));
144
146
 
145
147
  String id = implementation.startUpload(
146
148
  filePath,
@@ -150,7 +152,9 @@ public class UploaderPlugin extends Plugin {
150
152
  httpMethod,
151
153
  notificationTitle,
152
154
  maxRetries,
153
- mimeType
155
+ mimeType,
156
+ uploadType,
157
+ fileField
154
158
  );
155
159
  JSObject result = new JSObject();
156
160
  result.put("id", id);
package/dist/docs.json CHANGED
@@ -262,6 +262,46 @@
262
262
  "docs": "",
263
263
  "complexTypes": [],
264
264
  "type": "number | undefined"
265
+ },
266
+ {
267
+ "name": "uploadType",
268
+ "tags": [
269
+ {
270
+ "text": "0.0.2",
271
+ "name": "since"
272
+ },
273
+ {
274
+ "text": "The type of upload to use",
275
+ "name": "description"
276
+ },
277
+ {
278
+ "text": "'binary'",
279
+ "name": "default"
280
+ }
281
+ ],
282
+ "docs": "",
283
+ "complexTypes": [],
284
+ "type": "'binary' | 'multipart' | undefined"
285
+ },
286
+ {
287
+ "name": "fileField",
288
+ "tags": [
289
+ {
290
+ "text": "0.0.2",
291
+ "name": "since"
292
+ },
293
+ {
294
+ "text": "The form field name for the file when using multipart",
295
+ "name": "description"
296
+ },
297
+ {
298
+ "text": "'file'",
299
+ "name": "default"
300
+ }
301
+ ],
302
+ "docs": "",
303
+ "complexTypes": [],
304
+ "type": "string | undefined"
265
305
  }
266
306
  ]
267
307
  },
@@ -47,6 +47,18 @@ export interface uploadOption {
47
47
  * @description The maximum number of retries
48
48
  */
49
49
  maxRetries?: number;
50
+ /**
51
+ * @since 0.0.2
52
+ * @description The type of upload to use
53
+ * @default 'binary'
54
+ */
55
+ uploadType?: "binary" | "multipart";
56
+ /**
57
+ * @since 0.0.2
58
+ * @description The form field name for the file when using multipart
59
+ * @default 'file'
60
+ */
61
+ fileField?: string;
50
62
  }
51
63
  export interface UploadEvent {
52
64
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport interface uploadOption {\n /**\n * @since 0.0.1\n * @description The file path of the file to upload\n */\n filePath: string;\n /**\n * @since 0.0.1\n * @description The url of the server\n */\n serverUrl: string;\n /**\n * @since 0.0.1\n * @default 'Uploading'\n * @description The title of the notification\n * Android only\n */\n notificationTitle?: number;\n /**\n * @since 0.0.1\n * @description The headers to send with the request\n */\n headers: {\n [key: string]: string;\n };\n /**\n * @since 0.0.1\n * @description The method to use for the request\n * @default 'POST'\n */\n method?: \"PUT\" | \"POST\";\n /**\n * @since 0.0.1\n * @description The mime type to use for the request\n */\n mimeType?: string;\n /**\n * @since 0.0.1\n * @description The parameters to send with the request\n */\n parameters?: { [key: string]: string };\n /**\n * @since 0.0.1\n * @description The maximum number of retries\n */\n maxRetries?: number;\n}\nexport interface UploadEvent {\n /**\n * Current status of upload, between 0 and 100.\n *\n * @since 0.0.1\n */\n name: \"uploading\" | \"completed\" | \"failed\";\n /**\n * @since 0.0.1\n * @description The payload of the event\n * @default { percent: 0, error: '', statusCode: 0 }\n */\n payload: {\n /**\n * @since 0.0.1\n * @description The percent of the upload\n */\n percent?: number;\n /**\n * @since 0.0.1\n * @description The error of the upload\n */\n error?: string;\n /**\n * @since 0.0.1\n * @description The status code of the upload\n */\n statusCode?: number;\n };\n /**\n * @since 0.0.1\n * @description The id of the upload\n */\n id: string;\n}\n\nexport interface UploaderPlugin {\n /**\n * @since 0.0.1\n * @description Start the upload\n * @param options uploadOption\n * @returns { id: string }\n */\n startUpload(options: uploadOption): Promise<{ id: string }>;\n /**\n * @since 0.0.1\n * @description Remove the upload\n * @param options\n * @returns { void }\n */\n removeUpload(options: { id: string }): Promise<void>;\n /**\n * @since 0.0.1\n * @description Add a listener for the upload events\n * @param eventName\n * @param listenerFunc\n * @returns { PluginListenerHandle }\n */\n addListener(\n eventName: \"events\",\n listenerFunc: (state: UploadEvent) => void,\n ): Promise<PluginListenerHandle>;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport interface uploadOption {\n /**\n * @since 0.0.1\n * @description The file path of the file to upload\n */\n filePath: string;\n /**\n * @since 0.0.1\n * @description The url of the server\n */\n serverUrl: string;\n /**\n * @since 0.0.1\n * @default 'Uploading'\n * @description The title of the notification\n * Android only\n */\n notificationTitle?: number;\n /**\n * @since 0.0.1\n * @description The headers to send with the request\n */\n headers: {\n [key: string]: string;\n };\n /**\n * @since 0.0.1\n * @description The method to use for the request\n * @default 'POST'\n */\n method?: \"PUT\" | \"POST\";\n /**\n * @since 0.0.1\n * @description The mime type to use for the request\n */\n mimeType?: string;\n /**\n * @since 0.0.1\n * @description The parameters to send with the request\n */\n parameters?: { [key: string]: string };\n /**\n * @since 0.0.1\n * @description The maximum number of retries\n */\n maxRetries?: number;\n /**\n * @since 0.0.2\n * @description The type of upload to use\n * @default 'binary'\n */\n uploadType?: \"binary\" | \"multipart\";\n /**\n * @since 0.0.2\n * @description The form field name for the file when using multipart\n * @default 'file'\n */\n fileField?: string;\n}\nexport interface UploadEvent {\n /**\n * Current status of upload, between 0 and 100.\n *\n * @since 0.0.1\n */\n name: \"uploading\" | \"completed\" | \"failed\";\n /**\n * @since 0.0.1\n * @description The payload of the event\n * @default { percent: 0, error: '', statusCode: 0 }\n */\n payload: {\n /**\n * @since 0.0.1\n * @description The percent of the upload\n */\n percent?: number;\n /**\n * @since 0.0.1\n * @description The error of the upload\n */\n error?: string;\n /**\n * @since 0.0.1\n * @description The status code of the upload\n */\n statusCode?: number;\n };\n /**\n * @since 0.0.1\n * @description The id of the upload\n */\n id: string;\n}\n\nexport interface UploaderPlugin {\n /**\n * @since 0.0.1\n * @description Start the upload\n * @param options uploadOption\n * @returns { id: string }\n */\n startUpload(options: uploadOption): Promise<{ id: string }>;\n /**\n * @since 0.0.1\n * @description Remove the upload\n * @param options\n * @returns { void }\n */\n removeUpload(options: { id: string }): Promise<void>;\n /**\n * @since 0.0.1\n * @description Add a listener for the upload events\n * @param eventName\n * @param listenerFunc\n * @returns { PluginListenerHandle }\n */\n addListener(\n eventName: \"events\",\n listenerFunc: (state: UploadEvent) => void,\n ): Promise<PluginListenerHandle>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nconst Uploader = registerPlugin(\"Uploader\", {\n web: () => import(\"./web\").then((m) => new m.UploaderWeb()),\n});\nexport * from \"./definitions\";\nexport { Uploader };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\nexport class UploaderWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.uploads = new Map();\n }\n async startUpload(options) {\n console.log(\"startUpload\", options);\n const id = Math.random().toString(36).substring(2, 15);\n const controller = new AbortController();\n const maxRetries = options.maxRetries || 3;\n this.uploads.set(id, { controller, retries: maxRetries });\n this.doUpload(id, options);\n return { id };\n }\n async removeUpload(options) {\n console.log(\"removeUpload\", options);\n const upload = this.uploads.get(options.id);\n if (upload) {\n upload.controller.abort();\n this.uploads.delete(options.id);\n this.notifyListeners(\"events\", {\n name: \"cancelled\",\n id: options.id,\n payload: {},\n });\n }\n }\n async doUpload(id, options) {\n const { filePath, serverUrl, headers = {}, method = \"POST\", parameters = {}, } = options;\n const upload = this.uploads.get(id);\n if (!upload)\n return;\n try {\n const file = await this.getFileFromPath(filePath);\n if (!file)\n throw new Error(\"File not found\");\n const formData = new FormData();\n formData.append(\"file\", file);\n for (const [key, value] of Object.entries(parameters)) {\n formData.append(key, value);\n }\n const response = await fetch(serverUrl, {\n method,\n headers,\n body: method === \"PUT\" ? file : formData,\n signal: upload.controller.signal,\n });\n if (!response.ok)\n throw new Error(`HTTP error! status: ${response.status}`);\n this.notifyListeners(\"events\", {\n name: \"completed\",\n id,\n payload: { statusCode: response.status },\n });\n this.uploads.delete(id);\n }\n catch (error) {\n if (error.name === \"AbortError\")\n return;\n if (upload.retries > 0) {\n upload.retries--;\n console.log(`Retrying upload (retries left: ${upload.retries})`);\n setTimeout(() => this.doUpload(id, options), 1000);\n }\n else {\n this.notifyListeners(\"events\", {\n name: \"failed\",\n id,\n payload: { error: error.message },\n });\n this.uploads.delete(id);\n }\n }\n }\n async getFileFromPath(filePath) {\n // This is a simplified version. In a real-world scenario,\n // you might need to handle different types of paths or use a file system API.\n try {\n const response = await fetch(filePath);\n const blob = await response.blob();\n return new File([blob], filePath.split(\"/\").pop() || \"file\", {\n type: blob.type,\n });\n }\n catch (error) {\n console.error(\"Error getting file:\", error);\n return null;\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,QAAQ,GAAGA,mBAAc,CAAC,UAAU,EAAE;AAC5C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AAC/D,CAAC;;ACFM,MAAM,WAAW,SAASC,cAAS,CAAC;AAC3C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC,CAAC;AAC5B,QAAQ,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;AACjC,KAAK;AACL,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;AAC/B,QAAQ,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAC5C,QAAQ,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/D,QAAQ,MAAM,UAAU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OAAO,IAAI,CAAC;AACxB,SAAS;AACT,KAAK;AACL;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nconst Uploader = registerPlugin(\"Uploader\", {\n web: () => import(\"./web\").then((m) => new m.UploaderWeb()),\n});\nexport * from \"./definitions\";\nexport { Uploader };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\nexport class UploaderWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.uploads = new Map();\n }\n async startUpload(options) {\n console.log(\"startUpload\", options);\n const id = Math.random().toString(36).substring(2, 15);\n const controller = new AbortController();\n const maxRetries = options.maxRetries || 3;\n this.uploads.set(id, { controller, retries: maxRetries });\n this.doUpload(id, options);\n return { id };\n }\n async removeUpload(options) {\n console.log(\"removeUpload\", options);\n const upload = this.uploads.get(options.id);\n if (upload) {\n upload.controller.abort();\n this.uploads.delete(options.id);\n this.notifyListeners(\"events\", {\n name: \"cancelled\",\n id: options.id,\n payload: {},\n });\n }\n }\n async doUpload(id, options) {\n const { filePath, serverUrl, headers = {}, method = \"POST\", parameters = {}, } = options;\n const upload = this.uploads.get(id);\n if (!upload)\n return;\n try {\n const file = await this.getFileFromPath(filePath);\n if (!file)\n throw new Error(\"File not found\");\n const formData = new FormData();\n formData.append(\"file\", file);\n for (const [key, value] of Object.entries(parameters)) {\n formData.append(key, value);\n }\n const response = await fetch(serverUrl, {\n method,\n headers,\n body: method === \"PUT\" ? file : formData,\n signal: upload.controller.signal,\n });\n if (!response.ok)\n throw new Error(`HTTP error! status: ${response.status}`);\n this.notifyListeners(\"events\", {\n name: \"completed\",\n id,\n payload: { statusCode: response.status },\n });\n this.uploads.delete(id);\n }\n catch (error) {\n if (error.name === \"AbortError\")\n return;\n if (upload.retries > 0) {\n upload.retries--;\n console.log(`Retrying upload (retries left: ${upload.retries})`);\n setTimeout(() => this.doUpload(id, options), 1000);\n }\n else {\n this.notifyListeners(\"events\", {\n name: \"failed\",\n id,\n payload: { error: error.message },\n });\n this.uploads.delete(id);\n }\n }\n }\n async getFileFromPath(filePath) {\n // This is a simplified version. In a real-world scenario,\n // you might need to handle different types of paths or use a file system API.\n try {\n const response = await fetch(filePath);\n const blob = await response.blob();\n return new File([blob], filePath.split(\"/\").pop() || \"file\", {\n type: blob.type,\n });\n }\n catch (error) {\n console.error(\"Error getting file:\", error);\n return null;\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,QAAQ,GAAGA,mBAAc,CAAC,UAAU,EAAE;AAC5C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AAC/D,CAAC;;ACFM,MAAM,WAAW,SAASC,cAAS,CAAC;AAC3C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE;AAChC;AACA,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;AAC/B,QAAQ,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC;AAC3C,QAAQ,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC;AAC9D,QAAQ,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE;AAChD,QAAQ,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC;AAClD,QAAQ,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AACjE,QAAQ,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;AAClC,QAAQ,OAAO,EAAE,EA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AAClC,oBAAoB,EAAE;AACtB,oBAAoB,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE;AACrD,iBAAiB,CAAC;AAClB,gBAAgB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;AACvC;AACA;AACA;AACA,IAAI,MAAM,eAAe,CAAC,QAAQ,EAAE;AACpC;AACA;AACA,QAAQ,IAAI;AACZ,YAAY,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC;AAClD,YAAY,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE;AAC9C,YAAY,OAAO,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,MAAM,EAAE;AACzE,gBAAgB,IAAI,EAAE,IAAI,CAAC,IAAI;AAC/B,aAAa,CAAC;AACd;AACA,QAAQ,OAAO,KAAK,EAAE;AACtB,YAAY,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC;AACvD,YAAY,OAAO,IAAI;AACvB;AACA;AACA;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nconst Uploader = registerPlugin(\"Uploader\", {\n web: () => import(\"./web\").then((m) => new m.UploaderWeb()),\n});\nexport * from \"./definitions\";\nexport { Uploader };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\nexport class UploaderWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.uploads = new Map();\n }\n async startUpload(options) {\n console.log(\"startUpload\", options);\n const id = Math.random().toString(36).substring(2, 15);\n const controller = new AbortController();\n const maxRetries = options.maxRetries || 3;\n this.uploads.set(id, { controller, retries: maxRetries });\n this.doUpload(id, options);\n return { id };\n }\n async removeUpload(options) {\n console.log(\"removeUpload\", options);\n const upload = this.uploads.get(options.id);\n if (upload) {\n upload.controller.abort();\n this.uploads.delete(options.id);\n this.notifyListeners(\"events\", {\n name: \"cancelled\",\n id: options.id,\n payload: {},\n });\n }\n }\n async doUpload(id, options) {\n const { filePath, serverUrl, headers = {}, method = \"POST\", parameters = {}, } = options;\n const upload = this.uploads.get(id);\n if (!upload)\n return;\n try {\n const file = await this.getFileFromPath(filePath);\n if (!file)\n throw new Error(\"File not found\");\n const formData = new FormData();\n formData.append(\"file\", file);\n for (const [key, value] of Object.entries(parameters)) {\n formData.append(key, value);\n }\n const response = await fetch(serverUrl, {\n method,\n headers,\n body: method === \"PUT\" ? file : formData,\n signal: upload.controller.signal,\n });\n if (!response.ok)\n throw new Error(`HTTP error! status: ${response.status}`);\n this.notifyListeners(\"events\", {\n name: \"completed\",\n id,\n payload: { statusCode: response.status },\n });\n this.uploads.delete(id);\n }\n catch (error) {\n if (error.name === \"AbortError\")\n return;\n if (upload.retries > 0) {\n upload.retries--;\n console.log(`Retrying upload (retries left: ${upload.retries})`);\n setTimeout(() => this.doUpload(id, options), 1000);\n }\n else {\n this.notifyListeners(\"events\", {\n name: \"failed\",\n id,\n payload: { error: error.message },\n });\n this.uploads.delete(id);\n }\n }\n }\n async getFileFromPath(filePath) {\n // This is a simplified version. In a real-world scenario,\n // you might need to handle different types of paths or use a file system API.\n try {\n const response = await fetch(filePath);\n const blob = await response.blob();\n return new File([blob], filePath.split(\"/\").pop() || \"file\", {\n type: blob.type,\n });\n }\n catch (error) {\n console.error(\"Error getting file:\", error);\n return null;\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,QAAQ,GAAGA,mBAAc,CAAC,UAAU,EAAE;IAC5C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/D,CAAC;;ICFM,MAAM,WAAW,SAASC,cAAS,CA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AAK,CAAC,QAAQ,CAAC,CAAC;IACnD,YAAY,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC/C,YAAY,OAAO,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,MAAM,EAAE;IACzE,gBAAgB,IAAI,EAAE,IAAI,CAAC,IAAI;IAC/B,aAAa,CAAC,CAAC;IACf,SAAS;IACT,QAAQ,OAAO,KAAK,EAAE;IACtB,YAAY,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;IACxD,YAAY,OAAO,IAAI,CAAC;IACxB,SAAS;IACT,KAAK;IACL;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nconst Uploader = registerPlugin(\"Uploader\", {\n web: () => import(\"./web\").then((m) => new m.UploaderWeb()),\n});\nexport * from \"./definitions\";\nexport { Uploader };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from \"@capacitor/core\";\nexport class UploaderWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.uploads = new Map();\n }\n async startUpload(options) {\n console.log(\"startUpload\", options);\n const id = Math.random().toString(36).substring(2, 15);\n const controller = new AbortController();\n const maxRetries = options.maxRetries || 3;\n this.uploads.set(id, { controller, retries: maxRetries });\n this.doUpload(id, options);\n return { id };\n }\n async removeUpload(options) {\n console.log(\"removeUpload\", options);\n const upload = this.uploads.get(options.id);\n if (upload) {\n upload.controller.abort();\n this.uploads.delete(options.id);\n this.notifyListeners(\"events\", {\n name: \"cancelled\",\n id: options.id,\n payload: {},\n });\n }\n }\n async doUpload(id, options) {\n const { filePath, serverUrl, headers = {}, method = \"POST\", parameters = {}, } = options;\n const upload = this.uploads.get(id);\n if (!upload)\n return;\n try {\n const file = await this.getFileFromPath(filePath);\n if (!file)\n throw new Error(\"File not found\");\n const formData = new FormData();\n formData.append(\"file\", file);\n for (const [key, value] of Object.entries(parameters)) {\n formData.append(key, value);\n }\n const response = await fetch(serverUrl, {\n method,\n headers,\n body: method === \"PUT\" ? file : formData,\n signal: upload.controller.signal,\n });\n if (!response.ok)\n throw new Error(`HTTP error! status: ${response.status}`);\n this.notifyListeners(\"events\", {\n name: \"completed\",\n id,\n payload: { statusCode: response.status },\n });\n this.uploads.delete(id);\n }\n catch (error) {\n if (error.name === \"AbortError\")\n return;\n if (upload.retries > 0) {\n upload.retries--;\n console.log(`Retrying upload (retries left: ${upload.retries})`);\n setTimeout(() => this.doUpload(id, options), 1000);\n }\n else {\n this.notifyListeners(\"events\", {\n name: \"failed\",\n id,\n payload: { error: error.message },\n });\n this.uploads.delete(id);\n }\n }\n }\n async getFileFromPath(filePath) {\n // This is a simplified version. In a real-world scenario,\n // you might need to handle different types of paths or use a file system API.\n try {\n const response = await fetch(filePath);\n const blob = await response.blob();\n return new File([blob], filePath.split(\"/\").pop() || \"file\", {\n type: blob.type,\n });\n }\n catch (error) {\n console.error(\"Error getting file:\", error);\n return null;\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,QAAQ,GAAGA,mBAAc,CAAC,UAAU,EAAE;IAC5C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/D,CAAC;;ICFM,MAAM,WAAW,SAASC,cAAS,CAAC;IAC3C,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;IAC3B,QAAQ,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE;IAChC;IACA,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;IAC/B,QAAQ,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC;IAC3C,QAAQ,MA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
3
- "version": "0.0.27",
3
+ "version": "7.1.1",
4
4
  "description": "Upload file natively",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -53,7 +53,7 @@
53
53
  "verify:web": "npm run build",
54
54
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
55
55
  "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --autocorrect --format",
56
- "eslint": "eslint . --ext .ts",
56
+ "eslint": "eslint .",
57
57
  "prettier": "prettier --config .prettierrc.js \"**/*.{css,html,ts,js,java}\"",
58
58
  "swiftlint": "node-swiftlint",
59
59
  "docgen": "docgen --api UploaderPlugin --output-readme README.md --output-json dist/docs.json",
@@ -63,36 +63,33 @@
63
63
  "prepublishOnly": "npm run build"
64
64
  },
65
65
  "devDependencies": {
66
- "@capacitor/android": "^6.0.0",
67
- "@capacitor/cli": "^6.0.0",
68
- "@capacitor/core": "^6.0.0",
66
+ "@capacitor/android": "^7.0.0",
67
+ "@capacitor/cli": "^7.0.0",
68
+ "@capacitor/core": "^7.0.0",
69
69
  "@capacitor/docgen": "^0.3.0",
70
- "@capacitor/ios": "^6.0.0",
70
+ "@capacitor/ios": "^7.0.0",
71
71
  "@ionic/eslint-config": "^0.4.0",
72
72
  "@ionic/prettier-config": "^4.0.0",
73
- "@ionic/swiftlint-config": "^1.1.2",
74
- "@types/node": "^20.12.12",
75
- "@typescript-eslint/eslint-plugin": "^7.11.0",
76
- "@typescript-eslint/parser": "^7.11.0",
73
+ "@ionic/swiftlint-config": "^2.0.0",
74
+ "@types/node": "^22.13.1",
77
75
  "eslint": "^8.57.0",
78
- "eslint-plugin-import": "^2.29.1",
79
- "prettier": "^3.2.5",
80
- "prettier-plugin-java": "^2.6.0",
81
- "rimraf": "^5.0.7",
82
- "rollup": "^4.18.0",
83
- "swiftlint": "^1.0.2",
84
- "typescript": "^5.4.5"
76
+ "eslint-plugin-import": "^2.31.0",
77
+ "husky": "^9.1.7",
78
+ "prettier": "^3.4.2",
79
+ "prettier-plugin-java": "^2.6.7",
80
+ "rimraf": "^6.0.1",
81
+ "rollup": "^4.34.6",
82
+ "swiftlint": "^2.0.0",
83
+ "typescript": "^5.7.3"
85
84
  },
86
85
  "peerDependencies": {
87
- "@capacitor/core": "^6.0.0"
86
+ "@capacitor/core": ">=7.0.0"
88
87
  },
89
- "prettier": "@ionic/prettier-config",
90
88
  "eslintConfig": {
91
- "extends": "@ionic/eslint-config/recommended",
92
- "rules": {
93
- "@typescript-eslint/prefer-optional-chain": "off"
94
- }
89
+ "extends": "@ionic/eslint-config/recommended"
95
90
  },
91
+ "prettier": "@ionic/prettier-config",
92
+ "swiftlint": "@ionic/swiftlint-config",
96
93
  "capacitor": {
97
94
  "ios": {
98
95
  "src": "ios"
@@ -100,6 +97,5 @@
100
97
  "android": {
101
98
  "src": "android"
102
99
  }
103
- },
104
- "packageManager": "pnpm@9.9.0+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1"
100
+ }
105
101
  }