Skip to content

Commit 5c47b5b

Browse files
docs: add example code to the docs
1 parent b2a3589 commit 5c47b5b

File tree

1 file changed

+88
-2
lines changed

1 file changed

+88
-2
lines changed

src/index.doc.md

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,92 @@ The feature can validate both:
238238

239239
Take a look at {@link module:@admin-bro/upload.UploadOptions UploadOptions} here as well.
240240

241-
## Example
241+
## Example models and addon configurations
242242

243-
in the repository there is an `example-app` folder - check it out if you need more information.
243+
### Sequelize database with Google Cloud
244+
245+
Take a look at an example product upload schema:
246+
247+
```javascript
248+
export const ProductModel = sequelize.define('Products', {
249+
// Model attributes are defined here
250+
id: {
251+
primaryKey: true,
252+
type: DataTypes.UUID,
253+
defaultValue: UUIDV4,
254+
},
255+
name: {
256+
allowNull: false,
257+
type: DataTypes.STRING,
258+
},
259+
description: {
260+
type: DataTypes.TEXT,
261+
allowNull: true,
262+
},
263+
images: {
264+
type: DataTypes.JSONB,
265+
allowNull: true,
266+
},
267+
mainImage: {
268+
type: DataTypes.JSONB,
269+
allowNull: true,
270+
}
271+
}, {
272+
// Other model options go here
273+
})
274+
```
275+
276+
It has 2 fields `images` and `topImage`. Let's define that images will have a multi-upload
277+
feature and `topImage` single-upload feature.
278+
279+
By setting them as JSONB type we ensure that the plugin will setup their sub-properties as regular
280+
strings (single-upload) or arrays (multi-upload).
281+
282+
To setup upload for 2 files we have to invoke `uploadFeature` twice as well:
283+
284+
```javascript
285+
286+
const validation = {
287+
mimeTypes: ['image/jpeg', 'image/png'],
288+
}
289+
290+
const features = [
291+
uploadFileFeature({
292+
properties: {
293+
file: 'images.file',
294+
filePath: 'images.path',
295+
filename: 'images.filename',
296+
filesToDelete: 'images.toDelete',
297+
key: 'images.key',
298+
mimeType: 'images.mimeType',
299+
bucket: 'images.bucket',
300+
},
301+
multiple: true,
302+
provider: {
303+
gcp: {
304+
bucket: process.env.PRODUCTS_BUCKET as string,
305+
expires: 0,
306+
},
307+
},
308+
validation,
309+
}),
310+
uploadFeature({
311+
properties: {
312+
file: 'topImage.file',
313+
filePath: 'topImage.path',
314+
filename: 'topImage.filename',
315+
filesToDelete: 'topImage.toDelete',
316+
key: 'topImage.key',
317+
mimeType: 'topImage.mimeType',
318+
bucket: 'topImage.bucket',
319+
},
320+
provider: {
321+
gcp: {
322+
bucket: process.env.TOP_IMAGE_BUCKET as string,
323+
expires: 0,
324+
},
325+
},
326+
validation,
327+
}),
328+
]
329+
```

0 commit comments

Comments
 (0)