Support
Quality
Security
License
Reuse
kandi has reviewed react-native-image-picker and discovered the below as its top functions. This is intended to give you an instant insight into react-native-image-picker implemented functionality, and help decide if they suit your requirements.
:sunrise_over_mountains: A React Native module that allows you to use native UI to select media from the device library or directly from the camera.
Install
yarn add react-native-image-picker
# RN >= 0.60
cd ios && pod install
# RN < 0.60
react-native link react-native-image-picker
Methods
import {launchCamera, launchImageLibrary} from 'react-native-image-picker';
TypeError: undefined is not an object (evaluating '_this.camera = _ref')
import { useRef } from 'react';
...
const cameraRef = useRef<Camera>(null);
...
<Camera ref={cameraRef} ... />
React Native: Backend retrieves 'undefined' when uploading images
export function RNScreen(){
let photo = {
uri: '',
type: 'image/jpeg',
name: 'image.jpg',
};
launchImageLibrary(options, response => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.errorCode) {
console.log('ImagePicker Error: ', response.errorCode);
} else if (response.assets) {
photo.uri =
Platform.OS === 'android'
? String(response.assets[0].uri)
: String(response.assets[0].uri).replace('file://', '');
}
});
}
let data = new FormData();
data.append('images', photo);
let config = {
Authorization: AUTH_HEADER,
'Content-Type': 'multipart/form-data',
};
axios.post(API_URL + 'upload', data, {headers: config}).then(response => {
console.log(response.data);
});
-----------------------
export function RNScreen(){
let photo = {
uri: '',
type: 'image/jpeg',
name: 'image.jpg',
};
launchImageLibrary(options, response => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.errorCode) {
console.log('ImagePicker Error: ', response.errorCode);
} else if (response.assets) {
photo.uri =
Platform.OS === 'android'
? String(response.assets[0].uri)
: String(response.assets[0].uri).replace('file://', '');
}
});
}
let data = new FormData();
data.append('images', photo);
let config = {
Authorization: AUTH_HEADER,
'Content-Type': 'multipart/form-data',
};
axios.post(API_URL + 'upload', data, {headers: config}).then(response => {
console.log(response.data);
});
java.lang.NoSuchMethodError: No virtual method setSkipClientToken(Z)V in class Lcom/facebook/GraphRequest;
implementation 'com.facebook.android:facebook-marketing:[4,5)'
implementation 'com.facebook.android:facebook-marketing:latest.release'
-----------------------
implementation 'com.facebook.android:facebook-marketing:[4,5)'
implementation 'com.facebook.android:facebook-marketing:latest.release'
CocoaPods could not find compatible versions for pod "Firebase/CoreOnly" on React Native ios
$FirebaseSDKVersion = '8.10.0'
After taking image using react-native-image-picker but Failed to submit via Laravel API
const blob = await new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.onload = function () {
resolve(xhr.response);
};
xhr.onerror = function (e) {
reject(new TypeError("Network request failed"));
};
xhr.responseType = "blob";
xhr.open("GET", localPath, true);
xhr.send(null);
});
// Code to upload to BLOB data to the server here
// We're done with the blob, close and release it
blob.close();
this permision (android.permission.QUERY_ALL_PACKAGES) was automatically added to Manifest
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:node="remove" tools:ignore="QueryAllPackagesPermission" />
react-native android getting Blob JSON instead of image file in S3 pre-signed URL
export const save = async (data, uri, type) =>
await fetch(uri, {
method: 'PUT',
headers: {
Accept: 'application/json',
'Content-Type': type
},
body: data
});
React Native Error: Project with path ':expo-modules-core' could not be found in project ':react-native-reanimated'
npx install-expo-modules
react-native-image-picker getting reverse height and width
import ImagePicker from 'react-native-image-crop-picker';
ImagePicker.openCamera({
width: 768,
height: 1024,
cropping: false,
}).then(image => {
console.log(image)
})
how can i convert image uri to base64?
import RNFS from 'react-native-fs';
//base64 res
var data = await RNFS.readFile( "file://path-to-file", 'base64').then(res => { return res });
QUESTION
Cannot Read Property Show of Undefined When Using DocumentPicker.show() in React Native
Asked 2022-Mar-22 at 18:08I followed some answers from here that are similar to my issues. But unfortunately, the error is not removed. That is why I asked here again.
This is an old versioned React Native
project where react-native-document-picker
version was 2.1.0
. When I upgraded the version to 8.0.0
, the error shows as the following screenshot:
The current files are as like below;
android/settings.gradle
...
include ':react-native-document-picker'
project(':react-native-document-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-document-picker/android')
...
android/app/build.gradle
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
...
...
implementation project(':react-native-document-picker')
}
package.json
{
"name": "awesomeproject",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@react-native-community/datetimepicker": "^6.0.2",
"@react-navigation/drawer": "^6.3.1",
"@react-navigation/native": "^6.0.8",
"@react-navigation/stack": "^6.1.1",
"axios": "^0.26.1",
"moment": "^2.29.1",
"native-base": "^3.3.7",
"react": "17.0.2",
"react-native": "0.67.2",
"react-native-action-button": "^2.8.5",
"react-native-document-picker": "^8.0.0",
"react-native-dropdownalert": "^4.5.1",
"react-native-fcm": "^16.2.4",
"react-native-fetch-blob": "^0.10.8",
"react-native-fs": "^2.19.0",
"react-native-gesture-handler": "^2.3.2",
"react-native-image-picker": "^4.7.3",
"react-native-iphone-x-helper": "^1.3.1",
"react-native-keyboard-aware-scroll-view": "^0.9.5",
"react-native-keyboard-spacer": "^0.4.1",
"react-native-loading-spinner-overlay": "^3.0.0",
"react-native-modal-datetime-picker": "^13.1.0",
"react-native-modalbox": "^2.0.2",
"react-native-reanimated": "^2.4.1",
"react-native-safe-area-context": "^4.1.2",
"react-native-screens": "^3.13.0",
"react-native-simple-radio-button": "^2.7.4",
"react-native-simple-toast": "^1.1.3",
"react-native-svg": "^12.3.0",
"react-native-swiper": "^1.6.0",
"react-native-vector-icons": "^9.1.0",
"react-redux": "^7.2.6",
"redux": "^4.1.2",
"redux-logger": "^3.0.6",
"redux-saga": "^1.1.3"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"eslint": "7.14.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.66.2",
"react-test-renderer": "17.0.2"
},
"jest": {
"preset": "react-native"
}
}
app.js
import {DocumentPicker, DocumentPickerUtil} from 'react-native-document-picker';
pressOnAttach() {
Keyboard.dismiss();
this.refs.NoticeTitle.blur();
this.refs.NoticeDescription.blur();
setTimeout(() => {
DocumentPicker.show({
filetype: [DocumentPickerUtil.allFiles()],
}, (error, res) => {
if (error === null) {
setTimeout(() => {
if (!this.checkFileExtension(res.fileName)) {
alert(AppText.VALID_EXTENSION_MESSAGE)
} else {
this.generateList(res.uri, res.fileName, res.fileSize);
}
}, 1000)
}
});
}, 1000)
}
When I console.log
the DocumentPicker
and DocumentPickerUtil
, it returns undefined
always.
Could anyone help me please to fix this issue? Thanks in advance!
ANSWER
Answered 2022-Mar-22 at 18:08The reason you are getting DocumentPicker undefined is the react-native-document-picker
version 8.0.0
has been updated since version 2.1.0
which code you've posted.
According to the library doc, you have to import the DocumentPicker differently. And the util DocumentPickerUtil is also not available to the updated version. For react-native-document-picker
version 8.0.0
you have to import in the following way
import DocumentPicker, { types } from 'react-native-document-picker';
And also DocumentPicker.show
method is no longer available you have to use the DocumentPicker.pick
method.
Ref:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit