Skip to content

Commit 7022075

Browse files
authored
Merge pull request #974 from byeokim/docs
Add content for copyAssetsFileIOS method
2 parents 47cf330 + 1936738 commit 7022075

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

README.md

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -443,16 +443,52 @@ Copies the file named `filename` in the Android app's res folder and copies it t
443443

444444
Note: Android only. Will overwrite destPath if it already exists.
445445

446-
### `copyAssetsFileIOS(imageUri: string, destPath: string, width: number, height: number, scale : number = 1.0, compression : number = 1.0, resizeMode : string = 'contain' ): Promise<string>`
446+
### (iOS only) `copyAssetsFileIOS(imageUri: string, destPath: string, width: number, height: number, scale?: number, compression?: number, resizeMode?: string): Promise<string>`
447447

448-
iOS-only (not available on Mac Catalyst): copies a file from camera-roll, that is prefixed with "assets-library://asset/asset.JPG?..."
449-
to a specific destination. It will download the original from iCloud if necessary.
448+
*Not available on Mac Catalyst.*
450449

451-
If width and height is > 0, the image will be resized to a specific size and a specific compression rate.
452-
If scale is below 1, the image will be scaled according to the scale-factor (between 0.0 and 1.0)
453-
The resizeMode is also considered.
450+
Reads an image file from Camera Roll and writes to `destPath`. This method [assumes the image file to be JPEG file](https://github.com/itinance/react-native-fs/blob/f2f8f4a058cd9acfbcac3b8cf1e08fa1e9b09786/RNFSManager.m#L752-L753). This method will download the original from iCloud if necessary.
454451

455-
*Video-Support:*
452+
#### Parameters
453+
454+
##### `imageUri` string (required)
455+
456+
URI of a file in Camera Roll. Can be [either of the following formats](https://github.com/itinance/react-native-fs/blob/f2f8f4a058cd9acfbcac3b8cf1e08fa1e9b09786/RNFSManager.m#L781-L785):
457+
458+
- `ph://CC95F08C-88C3-4012-9D6D-64A413D254B3/L0/001`
459+
- `assets-library://asset/asset.JPG?id=CC95F08C-88C3-4012-9D6D-64A413D254B3&ext=JPG`
460+
461+
##### `destPath` string (required)
462+
463+
Destination to which the copied file will be saved, e.g. `RNFS.TemporaryDirectoryPath + 'example.jpg'`.
464+
465+
##### `width` number (required)
466+
467+
Copied file's image width will be resized to `width`. [If 0 is provided, width won't be resized.](https://github.com/itinance/react-native-fs/blob/f2f8f4a058cd9acfbcac3b8cf1e08fa1e9b09786/RNFSManager.m#L808)
468+
469+
##### `height` number (required)
470+
471+
Copied file's image height will be resized to `height`. [If 0 is provided, height won't be resized.](https://github.com/itinance/react-native-fs/blob/f2f8f4a058cd9acfbcac3b8cf1e08fa1e9b09786/RNFSManager.m#L808)
472+
473+
##### `scale` number (optional)
474+
475+
Copied file's image will be scaled proportional to `scale` factor from `width` x `height`. If both `width` and `height` are 0, the image won't scale. Range is [0.0, 1.0] and default is 1.0.
476+
477+
##### `compression` number (optional)
478+
479+
Quality of copied file's image. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). Range is [0.0, 1.0] and default is 1.0.
480+
481+
##### `resizeMode` string (optional)
482+
483+
If `resizeMode` is 'contain', copied file's image will be scaled so that its larger dimension fits `width` x `height`. If `resizeMode` is other value than 'contain', the image will be scaled so that it completely fills `width` x `height`. Default is 'contain'. Refer to [PHImageContentMode](https://developer.apple.com/documentation/photokit/phimagecontentmode).
484+
485+
#### Return value
486+
487+
##### `Promise<string>`
488+
489+
Copied file's URI.
490+
491+
#### Video-Support
456492

457493
One can use this method also to create a thumbNail from a video in a specific size.
458494
Currently it is impossible to specify a concrete position, the OS will decide wich
@@ -462,10 +498,11 @@ To copy a video from assets-library and save it as a mp4-file, refer to copyAsse
462498
Further information: https://developer.apple.com/reference/photos/phimagemanager/1616964-requestimageforasset
463499
The promise will on success return the final destination of the file, as it was defined in the destPath-parameter.
464500

465-
### copyAssetsVideoIOS(videoUri: string, destPath: string): Promise<string>
501+
### (iOS only) `copyAssetsVideoIOS(videoUri: string, destPath: string): Promise<string>`
502+
503+
*Not available on Mac Catalyst.*
466504

467-
iOS-only (not available on Mac Catalyst): copies a video from assets-library, that is prefixed with 'assets-library://asset/asset.MOV?...'
468-
to a specific destination.
505+
Copies a video from assets-library, that is prefixed with 'assets-library://asset/asset.MOV?...' to a specific destination.
469506

470507
### `unlink(filepath: string): Promise<void>`
471508

0 commit comments

Comments
 (0)