getsentry / getsentry/sentry-react-native
Support File URIs for Attachments
- Dominant language
- TypeScript
- Stars
- 1.8k
- Forks
- 366
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 89
Description
I’d like to request that the Sentry React Native SDK expose the getDataFromUri function as a public API. Right now, I’m importing it privately like this:
``` typescript
import { NATIVE } from '@sentry/react-native/dist/js/wrapper';
const jsByteArray = await NATIVE.getDataFromUri(image.url);
if (bd) {
const attachment: Attachment = {
filename: file.name || `file_${0}.${mime.getType(file.mediaContentType)}`,
data: jsByteArray,
contentType: file.mediaContentType,
};
attachments.push(attachment);
}
```
Depending on an internal method isn’t ideal—it feels brittle and may stop working if the SDK changes. Exposing getDataFromUri (or providing a similar official method) would make it safer and more straightforward to attach user-supplied files in a feedback workflow.
Additionally, it would be great if the SDK directly supported attaching files via a platform-based file URI (e.g., file://...). The code could look like this:
``` typescript
const attachment: Attachment = {
filename: file.name || `file_${index}.${mime.getType(file.mediaContentType)}`,
uri: image.url, // "file://etc"
contentType: file.mediaContentType,
};
```
Internally, Sentry could then convert that URI into the data it needs. This would simplify the process for developers who want to attach files without manually handling the conversion. If there’s another recommended approach, I’d love to hear it—otherwise, making getDataFromUri public (and potentially enhancing it to handle URIs directly) would be a big help.
Contributor guide
Assessment
This issue has not been assessed yet.