@capgo/capacitor-uploader 0.0.7 → 0.0.10
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
|
@@ -121,6 +121,54 @@ uploadToCustomServer(filePath, serverUrl);
|
|
|
121
121
|
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
+
### Exemple with Capacitor Camera preview:
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { CameraPreview } from '@capgo/camera-preview'
|
|
128
|
+
import { Uploader } from '@capgo/capacitor-uploader';
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
async function record() {
|
|
132
|
+
await CameraPreview.startRecordVideo({ storeToFile: true })
|
|
133
|
+
await new Promise(resolve => setTimeout(resolve, 5000))
|
|
134
|
+
const fileUrl = await CameraPreview.stopRecordVideo()
|
|
135
|
+
console.log(fileUrl.videoFilePath)
|
|
136
|
+
await uploadVideo(fileUrl.videoFilePath)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function uploadVideo(filePath: string) {
|
|
140
|
+
Uploader.addListener('events', (event) => {
|
|
141
|
+
switch (event.name) {
|
|
142
|
+
case 'uploading':
|
|
143
|
+
console.log(`Upload progress: ${event.payload.percent}%`);
|
|
144
|
+
break;
|
|
145
|
+
case 'completed':
|
|
146
|
+
console.log('Upload completed successfully');
|
|
147
|
+
console.log('Server response status code:', event.payload.statusCode);
|
|
148
|
+
break;
|
|
149
|
+
case 'failed':
|
|
150
|
+
console.error('Upload failed:', event.payload.error);
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
try {
|
|
155
|
+
const result = await Uploader.startUpload({
|
|
156
|
+
filePath,
|
|
157
|
+
serverUrl: 'S#_PRESIGNED_URL',
|
|
158
|
+
method: 'PUT',
|
|
159
|
+
headers: {
|
|
160
|
+
'Content-Type': 'video/mp4',
|
|
161
|
+
},
|
|
162
|
+
mimeType: 'video/mp4',
|
|
163
|
+
});
|
|
164
|
+
console.log('Video uploaded successfully:', result.id);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
console.error('Error uploading video:', error);
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
124
172
|
## API
|
|
125
173
|
|
|
126
174
|
<docgen-index>
|
|
@@ -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.
|
|
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
|
-
|
|
64
|
-
context,
|
|
65
|
-
serverUrl
|
|
66
|
-
)
|
|
63
|
+
BinaryUploadRequest request = new BinaryUploadRequest(context, serverUrl)
|
|
67
64
|
.setMethod(httpMethod)
|
|
68
|
-
.
|
|
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() {
|
|
@@ -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() {
|