react-native-image-picker: fileName in Response is null, not undefined, contradicting Flow type

I’m using 0.26.10, but the type for ImagePickerResponse.fileName in the current version has not changed:

export interface ImagePickerResponse {
  // [other things...]
  fileName?: string;
}

At least in the old version I’m using, fileName is sometimes null, which goes against filename?: string; because it is neither absent, undefined, nor a string.

If I upgrade to the most recent version, will this be fixed by fileName being undefined instead of null? (If so, feel free to close this right away.) Or is this type still incorrect?

The snippet above is TypeScript, but I believe that index.js.flow in the npm package is generated from that file.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 17 (3 by maintainers)

Commits related to this issue

Most upvoted comments

One other way that seems to work for me

let path = response.uri;
if (Platform.OS === "ios") {
   path = "~" + path.substring(path.indexOf("/Documents"));
}
if (!response.fileName) response.fileName = path.split("/").pop();

I have that problem too but ios fileName: null

Workaround:

const ext = response.type ? response.type.split('/').pop() : 'png';
....
response.fileName || `upload.${ext}`,