Skip to content

Commit 1af33dc

Browse files
committed
docs: update MediaStore related docs
1 parent d881ef5 commit 1af33dc

File tree

1 file changed

+42
-33
lines changed

1 file changed

+42
-33
lines changed

README.md

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -394,24 +394,24 @@ await stream.close();
394394
* Creates a new media file in the MediaStore with the given `mimeType`. This will not create a file on the filesystem, but will create a reference in the MediaStore.
395395

396396
```ts
397-
// createMediaFile(fileDescriptor: FileDescriptor, mediatype: MediaCollections): Promise<string>
397+
// createMediaFile(fileDescription: FileDescription, mediatype: MediaCollections): Promise<string>
398398

399-
const fileDescriptor = { name: 'sample', parentFolder: 'MyAppFolder', mimeType: 'image/png' }
399+
const fileDescription = { name: 'sample', parentFolder: 'MyAppFolder', mimeType: 'image/png' }
400400

401-
const contentURI = await RNFS.MediaStore.createMediaFile(fileDescriptor, RNFS.MediaStore.MEDIA_IMAGE)
401+
const contentURI = await RNFS.MediaStore.createMediaFile(fileDescription, RNFS.MediaStore.MEDIA_IMAGE)
402402
```
403403

404404
### `updateMediaFile`
405405

406406
* Updates the media file in the MediaStore
407407

408408
```ts
409-
// updateMediaFile(uri: string, fileDescriptor: FileDescriptor, mediatype: MediaCollections): Promise<string>
409+
// updateMediaFile(uri: string, fileDescription: FileDescription, mediatype: MediaCollections): Promise<string>
410410

411411
const contentURI = 'content://media/external/images/media/123'
412-
const fileDescriptor = { name: 'sample-updated-filename', parentFolder: 'MyAppFolder', mimeType: 'image/png' }
412+
const fileDescription = { name: 'sample-updated-filename', parentFolder: 'MyAppFolder', mimeType: 'image/png' }
413413

414-
const contentURI = await RNFS.MediaStore.updateMediaFile(contentURI, fileDescriptor, RNFS.MediaStore.MEDIA_IMAGE)
414+
const contentURI = await RNFS.MediaStore.updateMediaFile(contentURI, fileDescription, RNFS.MediaStore.MEDIA_IMAGE)
415415
```
416416

417417
### `writeToMediaFile`
@@ -429,34 +429,37 @@ await RNFS.MediaStore.writeToMediaFile('content://media/external/images/media/12
429429
* Copies the file at `filepath` to the MediaStore with the given `mimeType`.
430430

431431
```ts
432-
// copyToMediaStore(fileDescriptor: filedescriptor, mediatype: MediaCollections, path: string): Promise<string>
432+
// copyToMediaStore(fileDescription: FileDescription, mediatype: MediaCollections, path: string): Promise<string>
433433

434-
const fileDescriptor = { name: 'sample', parentFolder: 'MyAppFolder', mimeType: 'image/png' }
434+
const fileDescription = { name: 'sample', parentFolder: 'MyAppFolder', mimeType: 'image/png' }
435435

436-
const contentURI = await RNFS.MediaStore.copyToMediaStore(fileDescriptor, RNFS.MediaStore.MEDIA_IMAGE, '/path/to/image/imageToCopy.png')
436+
const contentURI = await RNFS.MediaStore.copyToMediaStore(fileDescription, RNFS.MediaStore.MEDIA_IMAGE, '/path/to/image/imageToCopy.png')
437437
```
438438

439439
### `queryMediaStore`
440440

441441
* Queries the MediaStore for media files with the given `searchOptions`.
442442

443443
```ts
444-
// queryMediaStore(searchOptions: MediaStoreSearchOptions): Promise<MediaStoreQueryResult>
444+
// queryMediaStore(searchOptions: MediaStoreSearchOptions): Promise<MediaStoreFile | undefined>
445445

446-
await RNFS.MediaStore.queryMediaStore({
446+
// Query by URI
447+
const result = await RNFS.MediaStore.queryMediaStore({
447448
uri: 'content://media/external/images/media/123',
448-
fileName: ''
449-
relativePath: ''
450-
mediaType: RNFS.MediaStore.MEDIA_IMAGE;
449+
mediaType: RNFS.MediaStore.MEDIA_IMAGE
451450
})
452451

453-
// or
454-
await RNFS.MediaStore.queryMediaStore({
455-
uri: '',
456-
fileName: 'image.png'
457-
relativePath: 'MyAppFolder'
458-
mediaType: RNFS.MediaStore.MEDIA_IMAGE;
452+
// or query by filename and path
453+
const result = await RNFS.MediaStore.queryMediaStore({
454+
fileName: 'image.png',
455+
relativePath: 'MyAppFolder',
456+
mediaType: RNFS.MediaStore.MEDIA_IMAGE
459457
})
458+
459+
// result will be MediaStoreFile or undefined if not found
460+
if (result) {
461+
console.log(result.uri, result.name, result.size)
462+
}
460463
```
461464

462465
### `deleteFromMediaStore`
@@ -469,29 +472,35 @@ await RNFS.MediaStore.queryMediaStore({
469472
await RNFS.MediaStore.deleteFromMediaStore('content://media/external/images/media/123')
470473
```
471474

472-
## FileDescriptor
475+
## FileDescription
473476
```ts
474-
type FileDescriptor = {
475-
name: string;
476-
parentFolder: string;
477-
mimeType: string
477+
type FileDescription = {
478+
name: string;
479+
parentFolder: string;
480+
mimeType: string
478481
};
479482
```
480483

481484
## MediaStoreSearchOptions
482485
```ts
483-
type MediaStoreSearchOptions = {
484-
uri: string;
485-
fileName: string;
486-
relativePath: string;
487-
mediaType: MediaCollections
486+
type MediaStoreSearchOptions = {
487+
uri?: string;
488+
fileName?: string;
489+
relativePath?: string;
490+
mediaType: MediaCollections
488491
};
489492
```
490493

491-
## MediaStoreQueryResult
494+
## MediaStoreFile
492495
```ts
493-
type MediaStoreQueryResult = {
494-
contentUri: string;
496+
type MediaStoreFile = {
497+
uri: string;
498+
name: string;
499+
mimeType: string;
500+
size: number;
501+
dateAdded?: bigint;
502+
dateModified?: bigint;
503+
relativePath?: string;
495504
};
496505
```
497506

0 commit comments

Comments
 (0)