Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const tags = await Exify.read(uri)
console.log(tags)
```

> [!IMPORTANT]
> The `uri` must include a scheme (e.g. `file://`, `ph://`, `content://`). Bare file paths like `/var/mobile/.../image.jpg` are not supported and will throw an error.

> [!NOTE]
> On Android 10+, GPS data is redacted from `content://` URIs by default. The library automatically requests `ACCESS_MEDIA_LOCATION` at runtime to access unredacted location data. Your app must have media read access (`READ_MEDIA_IMAGES` or `READ_EXTERNAL_STORAGE`) granted first.
> If you're already using a library like [`expo-media-library`](https://docs.expo.dev/versions/latest/sdk/media-library/) that grants `ACCESS_MEDIA_LOCATION`, exify will use the existing grant.
Expand Down
11 changes: 9 additions & 2 deletions android/src/main/java/com/lodev09/exify/ExifyModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class ExifyModule(
val scheme = photoUri.scheme

if (scheme == null) {
RNLog.w(context, "Exify: Invalid URI: $uri")
promise.reject(ERROR_TAG, "Invalid URI: $uri")
RNLog.w(context, "Exify: URI must include a scheme (e.g. file://): $uri")
promise.reject(ERROR_TAG, "URI must include a scheme (e.g. file://): $uri")
return
}

Expand Down Expand Up @@ -108,6 +108,13 @@ class ExifyModule(
promise: Promise,
) {
val photoUri = Uri.parse(uri)

if (photoUri.scheme == null) {
RNLog.w(context, "Exify: URI must include a scheme (e.g. file://): $uri")
promise.reject(ERROR_TAG, "URI must include a scheme (e.g. file://): $uri")
return
}

val params = Arguments.createMap()

try {
Expand Down
20 changes: 20 additions & 0 deletions ios/Exify.mm
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ - (void)read:(NSString *)uri
resolve(tags);
}];
} else {
if ([uri hasPrefix:@"/"] || ![uri containsString:@"://"]) {
RCTLogWarn(@"Exify: URI must include a scheme (e.g. file://): %@", uri);
reject(@"Error",
[NSString stringWithFormat:@"URI must include a scheme (e.g. "
@"file://): %@",
uri],
nil);
return;
}

NSURL *url = [NSURL URLWithString:uri];
if (!url) {
RCTLogWarn(@"Exify: Invalid URI: %@", uri);
Expand Down Expand Up @@ -317,6 +327,16 @@ - (void)write:(NSString *)uri
});
}];
} else {
if ([uri hasPrefix:@"/"] || ![uri containsString:@"://"]) {
RCTLogWarn(@"Exify: URI must include a scheme (e.g. file://): %@", uri);
reject(@"Error",
[NSString stringWithFormat:@"URI must include a scheme (e.g. "
@"file://): %@",
uri],
nil);
return;
}

NSURL *url = [NSURL URLWithString:uri];
if (!url) {
reject(@"Error", @"Invalid URL", nil);
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import Exify from './NativeExify';
import type { ExifTags, ExifyWriteResult } from './types';

/**
* Read Exif metadata from an image.
* @param uri Image URI with a scheme (e.g. `file://`, `ph://`, `content://`). Bare file paths are not supported.
*/
export function read(uri: string): Promise<ExifTags | null> {
return Exify.read(uri) as Promise<ExifTags | null>;
}

/**
* Write Exif metadata into an image.
* @param uri Image URI with a scheme (e.g. `file://`, `ph://`, `content://`). Bare file paths are not supported.
* @param tags Exif tags to write.
*/
export function write(uri: string, tags: ExifTags): Promise<ExifyWriteResult> {
return Exify.write(uri, tags as Object) as Promise<ExifyWriteResult>;
}
Expand Down