Comments (10)
Guten Tag, Hans here.
Note
New features, bugfixes, updates and other improvements are all handled mostly by @mrousavy
in his free time.
To support @mrousavy
, please consider 💖 sponsoring him on GitHub 💖.
Sponsored issues will be prioritized.
from react-native-vision-camera.
Add a file:// prefix
from react-native-vision-camera.
Thanks, @mrousavy, but the file:// prefix is already included in res.path
returned from const res = await camera.current.takePhoto();
As I tried to explain in my original post, the folder the file was saved in doesn't exist when program control returns from takePhoto()
. For example, if res.path returned from takePhoto()
is "file:///private/var/mobile/Containers/Data/Application/629FC6E1-1F8F-46B9-8D08-1CAF06EC450A/tmp/29A98AB6-0B9C-4F34-9846-23D036EAD751.jpeg", then when takePhoto()
returns, the folder "/private/var/mobile/Containers/Data/Application/" exists, but the folder "/private/var/mobile/Containers/Data/Application/629FC6E1-1F8F-46B9-8D08-1CAF06EC450A/" does NOT exist.
I edited PhotoCaptureDelegate.swift to log the path and whether the file exists. It DOES exist immediately after taking the picture, but if I add code to check if that same file still exists, pod install, and re-run the app, the first file NO LONGER exists.
So, it seems to me the photo file along with its containing folder [uuid]/tmp is being deleted before control returns from takePhoto()
.
Here's the photoOutput
with my edits:
func photoOutput(_: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
defer {
removeGlobal()
}
if let error = error as NSError? {
promise.reject(error: .capture(.unknown(message: error.description)), cause: error)
return
}
do {
let path = try FileUtils.writePhotoToTempFile(photo: photo, metadataProvider: metadataProvider)
// Does the path of a previous photo still exist?
if FileManager.default.fileExists(atPath: "/private/var/mobile/Containers/Data/Application/629FC6E1-1F8F-46B9-8D08-1CAF06EC450A/tmp/29A98AB6-0B9C-4F34-9846-23D036EAD751.jpeg") {
print("Old path exists: /private/var/mobile/Containers/Data/Application/629FC6E1-1F8F-46B9-8D08-1CAF06EC450A/tmp/29A98AB6-0B9C-4F34-9846-23D036EAD751.jpeg")
} else {
print("Old path does not exist: /private/var/mobile/Containers/Data/Application/629FC6E1-1F8F-46B9-8D08-1CAF06EC450A/tmp/29A98AB6-0B9C-4F34-9846-23D036EAD751.jpeg")
}
// path of the photo we just took
print("Photo saved to path: \(path.absoluteString)")
let exif = photo.metadata["{Exif}"] as? [String: Any]
let width = exif?["PixelXDimension"]
let height = exif?["PixelYDimension"]
let exifOrientation = photo.metadata[String(kCGImagePropertyOrientation)] as? UInt32 ?? CGImagePropertyOrientation.up.rawValue
let cgOrientation = CGImagePropertyOrientation(rawValue: exifOrientation) ?? CGImagePropertyOrientation.up
let orientation = getOrientation(forExifOrientation: cgOrientation)
let isMirrored = getIsMirrored(forExifOrientation: cgOrientation)
// Verify the file exists for the photo we just took
if FileManager.default.fileExists(atPath: path.path) {
print("File exists at path: \(path.path)")
} else {
print("File does not exist at path: \(path.path)")
}
promise.resolve([
"path": path.absoluteString,
"width": width as Any,
"height": height as Any,
"orientation": orientation,
"isMirrored": isMirrored,
"isRawPhoto": photo.isRawPhoto,
"metadata": photo.metadata,
"thumbnail": photo.embeddedThumbnailPhotoFormat as Any,
])
} catch let error as CameraError {
promise.reject(error: error)
} catch {
promise.reject(error: .capture(.unknown(message: "An unknown error occured while capturing the photo!")), cause: error as NSError)
}
}
I hope this clarification is helpful! I very much appreciate help in resolving this issue. It seems so strange that takePhoto()
would create a file in a [uuid]/tmp folder, then delete that whole folder before returning. I'm guessing the delete is happening in the Swift code, or due to some Apple "feature". Or possibly, there is also a permissions issue such that the [uuid]/tmp folder used in RNVC's Swift code cannot be seen in an app that uses RNVC.
In case it matters: I'm running Xcode 15.1 on an M1 mac Mini, running macOS Sonoma 14.5.
from react-native-vision-camera.
I have a workaround!
const destPath = [where you want to store the photo]
const res = await camera.current.takePhoto();
// THE WORKAROUND:
const sourcePath = Platform.OS === 'ios' ? res.path.replace('file:///private', '') : res.path;
await RNFetchBlob.fs.mv(sourcePath, destPath);
So I was barking up a forest of wrong trees because I thought I had already checked that workaround. I'm a dummy, but at least I learned a little bit this week. (The fact that I'm a dummy I already knew.)
I'll leave this issue open since it seems to me that this is a bug: on iOS, res.path in my opinion should return a useable path like it does on Android.
@mrousavy thanks again for an outstandingly helpful component!
from react-native-vision-camera.
Related Issues (20)
- 💭 Question: Implementing Virtual Background and AR Try-On Glasses with Frame Processing HOT 2
- 💭 CodeScanner does not recognize Data Matrix code on a black background HOT 2
- 🐛 photo.orientation is wrong when outputOrientation = preview on Android HOT 2
- 🐛 OutputOrientation: "Duplicate label in when" HOT 1
- 💭 Add filter to photo when photo is taken HOT 2
- 💭 Obtaining camera calibration data HOT 5
- 🐛 Crash in Android release build HOT 5
- 🐛 Failed to convert NativeBuffer to SkImage HOT 2
- 🔧 RCT_NEW_ARCH_ENABLED=1 failed pod install HOT 2
- 🐛 Cannot debug via Google Chrome if using Android Native method marked as synchronous HOT 2
- 🐛 Crash in iOS release build when using SkiaFrameProcessor HOT 3
- 🐛 Cached apps freezer is freezing app on Google Pixel with Android 14 HOT 6
- 🐛 App Crashes when try to implement camera inside modal. HOT 1
- 💭 iOS photo quality vs native camera HOT 4
- 💭 Getting incorrect coordinates and bounds when using CodeScanner when scanning barcodes HOT 1
- 🔧 Failed to archive HOT 3
- 🐛 Landscape mode camera issue. HOT 1
- 🐛 Landscape mode camera issue HOT 3
- 🐛 Unable to record video more than 30 fps HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-vision-camera.