@frenchbaas/js 0.4.0 → 0.4.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.
- package/README.md +26 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -151,6 +151,32 @@ const { url, expires_in } = await bucket.getUrl(obj.id)
|
|
|
151
151
|
await bucket.delete(obj.id)
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
+
### Bucket privé — stocker et retrouver un fichier
|
|
155
|
+
|
|
156
|
+
Avec un bucket privé, l'URL signée expire après 1h. Il ne faut **pas** stocker l'URL — il faut stocker l'`id` de l'objet retourné par `upload()`, puis appeler `getUrl()` à chaque affichage.
|
|
157
|
+
|
|
158
|
+
**Workflow recommandé :**
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
// 1. Upload → récupérer l'id de l'objet
|
|
162
|
+
const obj = await bucket.upload(file, 'photo.jpg')
|
|
163
|
+
const objectId = obj.id // ex: "a1b2c3d4-..."
|
|
164
|
+
|
|
165
|
+
// 2. Stocker l'id dans une collection FrenchBaas (pas l'URL)
|
|
166
|
+
await client.collection('profils').update(userId, {
|
|
167
|
+
avatar_storage_id: objectId,
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
// 3. À l'affichage : récupérer l'id depuis la collection, puis générer l'URL
|
|
171
|
+
const profil = await client.collection('profils').getById(userId)
|
|
172
|
+
const storedId = profil.data.avatar_storage_id
|
|
173
|
+
|
|
174
|
+
const { url } = await bucket.getUrl(storedId)
|
|
175
|
+
// url → URL signée fraîche, valide 1h
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
> ⚠️ Ne stockez jamais l'URL signée — elle expire. Stockez toujours l'`id` de l'objet.
|
|
179
|
+
|
|
154
180
|
### Visibilité des buckets
|
|
155
181
|
|
|
156
182
|
| Visibilité | listObjects | upload / delete | getUrl |
|