@capgo/capacitor-uploader 0.0.9 → 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 +48 -0
- package/package.json +1 -1
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>
|