@umituz/react-native-firebase 1.13.57 → 1.13.59
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 +277 -0
- package/package.json +1 -1
- package/scripts/README.md +513 -0
- package/src/auth/README.md +339 -0
- package/src/auth/domain/README.md +264 -0
- package/src/auth/domain/errors/README.md +291 -0
- package/src/auth/infrastructure/config/README.md +239 -0
- package/src/auth/infrastructure/services/README.md +346 -0
- package/src/auth/infrastructure/stores/README.md +407 -0
- package/src/auth/presentation/hooks/README.md +442 -0
- package/src/domain/README.md +628 -0
- package/src/firestore/README.md +566 -0
- package/src/firestore/domain/README.md +325 -0
- package/src/firestore/domain/constants/README.md +332 -0
- package/src/firestore/domain/entities/README.md +286 -0
- package/src/firestore/domain/errors/README.md +389 -0
- package/src/firestore/infrastructure/config/README.md +239 -0
- package/src/firestore/infrastructure/middleware/README.md +316 -0
- package/src/firestore/infrastructure/repositories/README.md +425 -0
- package/src/firestore/infrastructure/services/README.md +332 -0
- package/src/firestore/types/pagination/README.md +332 -0
- package/src/firestore/utils/README.md +574 -0
- package/src/firestore/utils/dateUtils/README.md +171 -0
- package/src/firestore/utils/document-mapper.helper/README.md +309 -0
- package/src/firestore/utils/pagination.helper/README.md +298 -0
- package/src/firestore/utils/path-resolver/README.md +277 -0
- package/src/firestore/utils/query-builder/README.md +291 -0
- package/src/firestore/utils/quota-error-detector/README.md +355 -0
- package/src/infrastructure/README.md +408 -0
- package/src/infrastructure/config/README.md +262 -0
- package/src/presentation/README.md +556 -0
- package/src/storage/README.md +493 -0
- package/src/storage/deleter/README.md +370 -0
- package/src/storage/types/README.md +313 -0
- package/src/storage/uploader/README.md +409 -0
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
# Storage Uploader
|
|
2
|
+
|
|
3
|
+
Firebase Storage upload functionality supporting base64 images and file uploads from URIs.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides file upload capabilities to Firebase Storage with base64 image upload, URI upload, automatic MIME type detection, custom metadata support, and comprehensive error handling.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using Storage Uploader
|
|
12
|
+
|
|
13
|
+
1. **ALWAYS** use uploader functions (never Firebase Storage SDK directly)
|
|
14
|
+
2. **COMPRESS** images before upload (reduce bandwidth/storage)
|
|
15
|
+
3. **USE** organized storage paths (hierarchical structure)
|
|
16
|
+
4. **HANDLE** upload errors appropriately
|
|
17
|
+
5. **ADD** metadata for tracking and management
|
|
18
|
+
|
|
19
|
+
### Required Practices
|
|
20
|
+
|
|
21
|
+
1. **Use uploader functions** - Import from storage module
|
|
22
|
+
2. **Organize paths** - Use hierarchical structure (users/{userId}/...)
|
|
23
|
+
3. **Add metadata** - Attach custom metadata to uploads
|
|
24
|
+
4. **Compress images** - Reduce file size before upload
|
|
25
|
+
5. **Handle errors** - Show user-friendly error messages
|
|
26
|
+
6. **Use unique filenames** - Prevent overwrites
|
|
27
|
+
|
|
28
|
+
### Forbidden Practices
|
|
29
|
+
|
|
30
|
+
## ❌ NEVER
|
|
31
|
+
|
|
32
|
+
- Use Firebase Storage SDK directly in application code
|
|
33
|
+
- Upload without compression (images)
|
|
34
|
+
- Use flat storage structure
|
|
35
|
+
- Ignore upload errors
|
|
36
|
+
- Use predictable filenames (photo.jpg, avatar.jpg)
|
|
37
|
+
- Upload sensitive data without encryption
|
|
38
|
+
|
|
39
|
+
## ⚠️ Avoid
|
|
40
|
+
|
|
41
|
+
- Uploading large files without progress indication
|
|
42
|
+
- Not adding metadata to uploads
|
|
43
|
+
- Using sequential filenames
|
|
44
|
+
- Not organizing files hierarchically
|
|
45
|
+
- Ignoring MIME types
|
|
46
|
+
|
|
47
|
+
## Usage Strategies
|
|
48
|
+
|
|
49
|
+
### For Base64 Image Upload
|
|
50
|
+
|
|
51
|
+
**Strategy:** Use uploadBase64Image for camera/gallery photos.
|
|
52
|
+
|
|
53
|
+
**Import From:** `@umituz/react-native-firebase/storage` or `src/storage/uploader`
|
|
54
|
+
|
|
55
|
+
**When to Use:**
|
|
56
|
+
- Uploading photos from camera/gallery
|
|
57
|
+
- Base64 encoded image data
|
|
58
|
+
- Image picker returns base64
|
|
59
|
+
- Profile pictures, avatars
|
|
60
|
+
|
|
61
|
+
**Function:** `uploadBase64Image(base64, storagePath, options?)`
|
|
62
|
+
|
|
63
|
+
**Parameters:**
|
|
64
|
+
- `base64: string` - Base64 image data (with or without data URL prefix)
|
|
65
|
+
- `storagePath: string` - Destination path in Storage bucket
|
|
66
|
+
- `options?: UploadOptions` - Optional configuration (mimeType, customMetadata)
|
|
67
|
+
|
|
68
|
+
**Returns:** `Promise<UploadResult>`
|
|
69
|
+
- `downloadUrl: string` - Public download URL
|
|
70
|
+
- `storagePath: string` - Storage path
|
|
71
|
+
|
|
72
|
+
**Strategy:**
|
|
73
|
+
1. Compress image before upload
|
|
74
|
+
2. Generate unique filename (timestamp-based)
|
|
75
|
+
3. Organize path hierarchically
|
|
76
|
+
4. Add custom metadata
|
|
77
|
+
5. Handle errors appropriately
|
|
78
|
+
|
|
79
|
+
### For File Upload from URI
|
|
80
|
+
|
|
81
|
+
**Strategy:** Use uploadFile for file URIs (file://, content://).
|
|
82
|
+
|
|
83
|
+
**Import From:** `@umituz/react-native-firebase/storage` or `src/storage/uploader`
|
|
84
|
+
|
|
85
|
+
**When to Use:**
|
|
86
|
+
- File picker returns URI
|
|
87
|
+
- Document uploads
|
|
88
|
+
- Video files
|
|
89
|
+
- Files from device storage
|
|
90
|
+
|
|
91
|
+
**Function:** `uploadFile(uri, storagePath, options?)`
|
|
92
|
+
|
|
93
|
+
**Parameters:**
|
|
94
|
+
- `uri: string` - File URI (file://, content://, http://)
|
|
95
|
+
- `storagePath: string` - Destination path in Storage bucket
|
|
96
|
+
- `options?: UploadOptions` - Optional configuration
|
|
97
|
+
|
|
98
|
+
**Returns:** `Promise<UploadResult>`
|
|
99
|
+
|
|
100
|
+
**Strategy:**
|
|
101
|
+
1. Validate file URI
|
|
102
|
+
2. Check file size (limit large files)
|
|
103
|
+
3. Generate unique filename
|
|
104
|
+
4. Add metadata for tracking
|
|
105
|
+
5. Handle upload failures
|
|
106
|
+
|
|
107
|
+
### For MIME Type Detection
|
|
108
|
+
|
|
109
|
+
**Strategy:** Use getMimeType to detect content type from base64.
|
|
110
|
+
|
|
111
|
+
**Import From:** `@umituz/react-native-firebase/storage` or `src/storage/uploader`
|
|
112
|
+
|
|
113
|
+
**When to Use:**
|
|
114
|
+
- Auto-detect image type from base64
|
|
115
|
+
- Validate image format
|
|
116
|
+
- Set correct MIME type
|
|
117
|
+
|
|
118
|
+
**Function:** `getMimeType(base64): string`
|
|
119
|
+
|
|
120
|
+
**Supports:**
|
|
121
|
+
- `image/png` (data:image/png;base64,)
|
|
122
|
+
- `image/webp` (data:image/webp;base64,)
|
|
123
|
+
- `image/gif` (data:image/gif;base64,)
|
|
124
|
+
- `image/jpeg` (default)
|
|
125
|
+
|
|
126
|
+
**Strategy:**
|
|
127
|
+
1. Call getMimeType before upload
|
|
128
|
+
2. Use returned MIME type in options
|
|
129
|
+
3. Fallback to image/jpeg if unknown
|
|
130
|
+
|
|
131
|
+
### For Multiple File Upload
|
|
132
|
+
|
|
133
|
+
**Strategy:** Upload files sequentially with progress tracking.
|
|
134
|
+
|
|
135
|
+
**Import From:** `@umituz/react-native-firebase/storage` or `src/storage/uploader`
|
|
136
|
+
|
|
137
|
+
**When to Use:**
|
|
138
|
+
- Photo gallery uploads
|
|
139
|
+
- Batch document uploads
|
|
140
|
+
- Multiple file selection
|
|
141
|
+
|
|
142
|
+
**Implementation:**
|
|
143
|
+
1. Loop through files array
|
|
144
|
+
2. Upload each file with unique path
|
|
145
|
+
3. Track success/failure for each
|
|
146
|
+
4. Show progress to user
|
|
147
|
+
5. Return results array
|
|
148
|
+
|
|
149
|
+
**Batch Upload Strategy:**
|
|
150
|
+
- Upload sequentially (not parallel) - better error handling
|
|
151
|
+
- Track progress: `{ current: 3, total: 10 }`
|
|
152
|
+
- Collect failed uploads for retry
|
|
153
|
+
- Return detailed results
|
|
154
|
+
|
|
155
|
+
### For Profile Picture Upload
|
|
156
|
+
|
|
157
|
+
**Strategy:** Compress, upload, and update user profile.
|
|
158
|
+
|
|
159
|
+
**Import From:** `@umituz/react-native-firebase/storage` and auth/firestore
|
|
160
|
+
|
|
161
|
+
**When to Use:**
|
|
162
|
+
- User profile picture updates
|
|
163
|
+
- Avatar changes
|
|
164
|
+
- Image cropping/resizing needed
|
|
165
|
+
|
|
166
|
+
**Implementation Strategy:**
|
|
167
|
+
1. Compress image (max 1024x1024, quality 0.8)
|
|
168
|
+
2. Generate unique filename (avatar_timestamp.jpg)
|
|
169
|
+
3. Upload to users/{userId}/avatar/{filename}
|
|
170
|
+
4. Get download URL
|
|
171
|
+
5. Update Firestore user document
|
|
172
|
+
6. Delete old avatar if exists
|
|
173
|
+
|
|
174
|
+
### For Multiple Photos Upload
|
|
175
|
+
|
|
176
|
+
**Strategy:** Upload gallery photos with error handling.
|
|
177
|
+
|
|
178
|
+
**Import From:** `@umituz/react-native-firebase/storage` or `src/storage/uploader`
|
|
179
|
+
|
|
180
|
+
**When to Use:**
|
|
181
|
+
- Photo gallery creation
|
|
182
|
+
- Multiple image selection
|
|
183
|
+
- Batch photo uploads
|
|
184
|
+
|
|
185
|
+
**Implementation:**
|
|
186
|
+
1. Compress each image
|
|
187
|
+
2. Generate unique filenames
|
|
188
|
+
3. Upload to users/{userId}/photos/{filename}
|
|
189
|
+
4. Track each upload result
|
|
190
|
+
5. Return array of download URLs
|
|
191
|
+
6. Handle partial failures gracefully
|
|
192
|
+
|
|
193
|
+
## Storage Path Organization
|
|
194
|
+
|
|
195
|
+
### Path Strategy
|
|
196
|
+
|
|
197
|
+
**Import From:** Use in storagePath parameter
|
|
198
|
+
|
|
199
|
+
**Pattern:** Hierarchical structure with user-based organization
|
|
200
|
+
|
|
201
|
+
**User Files:**
|
|
202
|
+
- Avatar: `users/{userId}/avatar/avatar.jpg`
|
|
203
|
+
- Photos: `users/{userId}/photos/photo_{timestamp}.jpg`
|
|
204
|
+
- Documents: `users/{userId}/documents/{category}/{filename}.pdf`
|
|
205
|
+
- Temporary: `users/{userId}/temp/{timestamp}.jpg`
|
|
206
|
+
|
|
207
|
+
**Product Images:**
|
|
208
|
+
- Main: `products/{productId}/main.jpg`
|
|
209
|
+
- Gallery: `products/{productId}/gallery/{index}.jpg`
|
|
210
|
+
- Thumbnails: `products/{productId}/thumbnails/thumb.jpg`
|
|
211
|
+
|
|
212
|
+
**Content Files:**
|
|
213
|
+
- Posts: `content/posts/{postId}/featured.jpg`
|
|
214
|
+
- Videos: `content/videos/{videoId}/poster.jpg`
|
|
215
|
+
- Documents: `content/documents/{docId}/{filename}.pdf`
|
|
216
|
+
|
|
217
|
+
**Benefits:**
|
|
218
|
+
- Organized structure
|
|
219
|
+
- Easy to manage
|
|
220
|
+
- Simple user-based cleanup
|
|
221
|
+
- Clear ownership
|
|
222
|
+
|
|
223
|
+
## Metadata Strategy
|
|
224
|
+
|
|
225
|
+
### Custom Metadata
|
|
226
|
+
|
|
227
|
+
**Strategy:** Attach metadata for tracking and management.
|
|
228
|
+
|
|
229
|
+
**Import From:** Pass in UploadOptions
|
|
230
|
+
|
|
231
|
+
**Common Metadata:**
|
|
232
|
+
- `uploadedBy` - User ID who uploaded
|
|
233
|
+
- `originalFileName` - Original file name
|
|
234
|
+
- `type` - File type/category (avatar, document, etc.)
|
|
235
|
+
- `uploadedAt` - ISO timestamp
|
|
236
|
+
- `width` - Image width (for images)
|
|
237
|
+
- `height` - Image height (for images)
|
|
238
|
+
- `contentType` - Content description
|
|
239
|
+
|
|
240
|
+
**Usage:**
|
|
241
|
+
1. Create metadata object with key-value pairs
|
|
242
|
+
2. Pass in UploadOptions.customMetadata
|
|
243
|
+
3. Stored with file in Firebase Storage
|
|
244
|
+
4. Useful for audit trail and management
|
|
245
|
+
|
|
246
|
+
## Error Handling
|
|
247
|
+
|
|
248
|
+
### Common Errors
|
|
249
|
+
|
|
250
|
+
**Import From:** Handle errors from upload functions
|
|
251
|
+
|
|
252
|
+
**Error Types:**
|
|
253
|
+
- `NOT_INITIALIZED` - Firebase Storage not initialized
|
|
254
|
+
- `QUOTA_EXCEEDED` - Storage quota exceeded
|
|
255
|
+
- `UNAUTHORIZED` - User not authorized to upload
|
|
256
|
+
- `NETWORK_ERROR` - Network connection failed
|
|
257
|
+
- `INVALID_FILE` - Invalid file format or size
|
|
258
|
+
|
|
259
|
+
**Error Handling Strategy:**
|
|
260
|
+
1. Wrap upload in try-catch
|
|
261
|
+
2. Check error message for type
|
|
262
|
+
3. Return user-friendly error message
|
|
263
|
+
4. Log technical error for debugging
|
|
264
|
+
5. Provide retry option if appropriate
|
|
265
|
+
|
|
266
|
+
## Common Mistakes to Avoid
|
|
267
|
+
|
|
268
|
+
1. ❌ Not compressing images before upload
|
|
269
|
+
- ✅ Always compress images (quality 0.8, max 1024x1024)
|
|
270
|
+
|
|
271
|
+
2. ❌ Using flat storage structure
|
|
272
|
+
- ✅ Use hierarchical organization (users/{userId}/...)
|
|
273
|
+
|
|
274
|
+
3. ❌ Not adding metadata
|
|
275
|
+
- ✅ Attach custom metadata to all uploads
|
|
276
|
+
|
|
277
|
+
4. ❌ Using predictable filenames
|
|
278
|
+
- ✅ Use unique filenames (timestamp-based)
|
|
279
|
+
|
|
280
|
+
5. ❌ Not handling upload errors
|
|
281
|
+
- ✅ Show user-friendly error messages
|
|
282
|
+
|
|
283
|
+
6. ❌ Uploading large files without optimization
|
|
284
|
+
- ✅ Compress images and limit file sizes
|
|
285
|
+
|
|
286
|
+
## AI Agent Instructions
|
|
287
|
+
|
|
288
|
+
### When Uploading Single Image
|
|
289
|
+
|
|
290
|
+
1. Compress image before upload
|
|
291
|
+
2. Generate unique filename (timestamp or UUID)
|
|
292
|
+
3. Organize path hierarchically
|
|
293
|
+
4. Add metadata for tracking
|
|
294
|
+
5. Handle errors appropriately
|
|
295
|
+
6. Update database with download URL
|
|
296
|
+
|
|
297
|
+
### When Uploading Multiple Files
|
|
298
|
+
|
|
299
|
+
1. Loop through files array
|
|
300
|
+
2. Upload sequentially (not parallel)
|
|
301
|
+
3. Track success/failure for each file
|
|
302
|
+
4. Show progress to user
|
|
303
|
+
5. Return detailed results array
|
|
304
|
+
6. Handle partial failures gracefully
|
|
305
|
+
|
|
306
|
+
### When Organizing Storage Paths
|
|
307
|
+
|
|
308
|
+
1. Use hierarchical structure
|
|
309
|
+
2. Include user ID in path
|
|
310
|
+
3. Organize by file type/category
|
|
311
|
+
4. Use unique filenames
|
|
312
|
+
5. Keep paths consistent
|
|
313
|
+
|
|
314
|
+
### When Adding Metadata
|
|
315
|
+
|
|
316
|
+
1. Include uploadedBy (user ID)
|
|
317
|
+
2. Add upload timestamp
|
|
318
|
+
3. Include file type/category
|
|
319
|
+
4. Add original filename if available
|
|
320
|
+
5. Include image dimensions for photos
|
|
321
|
+
|
|
322
|
+
## Code Quality Standards
|
|
323
|
+
|
|
324
|
+
### TypeScript
|
|
325
|
+
|
|
326
|
+
- Use UploadResult type for return values
|
|
327
|
+
- Use UploadOptions for configuration
|
|
328
|
+
- Type all function parameters
|
|
329
|
+
- Handle errors properly
|
|
330
|
+
|
|
331
|
+
### File Naming
|
|
332
|
+
|
|
333
|
+
**Use These Patterns:**
|
|
334
|
+
- `avatar_{timestamp}.jpg`
|
|
335
|
+
- `photo_{index}_{timestamp}.jpg`
|
|
336
|
+
- `document_{uuid}.pdf`
|
|
337
|
+
- `{type}_{userId}_{timestamp}.jpg`
|
|
338
|
+
|
|
339
|
+
**Avoid These Patterns:**
|
|
340
|
+
- `avatar.jpg` (not unique)
|
|
341
|
+
- `photo1.jpg, photo2.jpg` (predictable)
|
|
342
|
+
- `user_avatar.jpg` (no timestamp)
|
|
343
|
+
|
|
344
|
+
### Error Handling
|
|
345
|
+
|
|
346
|
+
- Always wrap uploads in try-catch
|
|
347
|
+
- Return user-friendly error messages
|
|
348
|
+
- Log technical errors for debugging
|
|
349
|
+
- Provide retry option when appropriate
|
|
350
|
+
|
|
351
|
+
## Performance Considerations
|
|
352
|
+
|
|
353
|
+
### Image Compression
|
|
354
|
+
|
|
355
|
+
**Before Upload:**
|
|
356
|
+
- Resize to max 1024x1024 pixels
|
|
357
|
+
- Compress to JPEG quality 0.8
|
|
358
|
+
- Use expo-image-manipulator or similar
|
|
359
|
+
- Reduces bandwidth and storage costs
|
|
360
|
+
|
|
361
|
+
### Batch Uploads
|
|
362
|
+
|
|
363
|
+
**Sequential vs Parallel:**
|
|
364
|
+
- Upload sequentially for better error handling
|
|
365
|
+
- Parallel uploads faster but harder to track
|
|
366
|
+
- Recommend sequential for most cases
|
|
367
|
+
- Use parallel only for small batches (< 5 files)
|
|
368
|
+
|
|
369
|
+
### Storage Costs
|
|
370
|
+
|
|
371
|
+
**Optimization:**
|
|
372
|
+
- Compress images before upload
|
|
373
|
+
- Use appropriate image formats
|
|
374
|
+
- Delete old/unused files
|
|
375
|
+
- Monitor storage usage
|
|
376
|
+
|
|
377
|
+
## Related Documentation
|
|
378
|
+
|
|
379
|
+
- [Storage Module README](../README.md)
|
|
380
|
+
- [Storage Deleter README](../deleter/README.md)
|
|
381
|
+
- [Storage Types README](../types/README.md)
|
|
382
|
+
- [Firestore README](../../firestore/README.md)
|
|
383
|
+
|
|
384
|
+
## API Reference
|
|
385
|
+
|
|
386
|
+
### Main Functions
|
|
387
|
+
|
|
388
|
+
**Import Path:** `@umituz/react-native-firebase/storage` or `src/storage/uploader`
|
|
389
|
+
|
|
390
|
+
| Function | Parameters | Returns | Description |
|
|
391
|
+
|----------|-----------|---------|-------------|
|
|
392
|
+
| `uploadBase64Image` | base64, storagePath, options? | `Promise<UploadResult>` | Upload base64 image |
|
|
393
|
+
| `uploadFile` | uri, storagePath, options? | `Promise<UploadResult>` | Upload file from URI |
|
|
394
|
+
| `getMimeType` | base64 | `string` | Detect MIME type |
|
|
395
|
+
|
|
396
|
+
### Type Definitions
|
|
397
|
+
|
|
398
|
+
**UploadResult:**
|
|
399
|
+
- `downloadUrl: string` - Public download URL
|
|
400
|
+
- `storagePath: string` - Storage path
|
|
401
|
+
|
|
402
|
+
**UploadOptions:**
|
|
403
|
+
- `mimeType?: string` - Content type (auto-detected for base64)
|
|
404
|
+
- `customMetadata?: Record<string, string>` - Custom metadata
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
**Last Updated:** 2025-01-08
|
|
409
|
+
**Maintainer:** Storage Module Team
|