doc: Code fixes on saving & getting the photo in TAKING_PHOTOS.mdx (#1896)

code fixes on saving & getting the photo in TAKING_PHOTOS.mdx

- The variable path has been renamed to file, as camera.current.takePhoto() always returns a file
- CameraRoll.save() method has been updated to use file.path for saving the captured photo.
- fetch() method has been updated to use file.path on getting captured photo as blob
This commit is contained in:
Shiran Gabriel 2023-10-03 14:50:41 +05:30 committed by GitHub
parent 554b7416b1
commit 12c2987b85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -71,8 +71,8 @@ const photo = await camera.current.takePhoto({
Since the Photo is stored as a temporary file, you need to save it to the Camera Roll to permanentely store it. You can use [react-native-cameraroll](https://github.com/react-native-cameraroll/react-native-cameraroll) for this:
```ts
const path = await camera.current.takePhoto()
await CameraRoll.save(`file://${path}`, {
const file = await camera.current.takePhoto()
await CameraRoll.save(`file://${file.path}`, {
type: 'photo',
})
```
@ -82,8 +82,8 @@ await CameraRoll.save(`file://${path}`, {
To get the Photo's pixel data, you can use [`fetch(...)`](https://reactnative.dev/docs/network#using-fetch) to read the local file as a Blob:
```ts
const path = await camera.current.takePhoto()
const result = await fetch(`file://${path}`)
const file = await camera.current.takePhoto()
const result = await fetch(`file://${file.path}`)
const data = await result.blob();
```