React-native-document-picker not working in android - react-native

React-native-document-picker not working in android
after selecting image app stopped.
react-native ver:-59.5
react-native-document-picker --v:-3.2.4
I am using this code.
var results = await DocumentPicker.pickMultiple({
type: [DocumentPicker.types.images],
});
for(var res of results) {
this.setState({
getSecondFile:res,
chosepic_2:res.uri
})
console.log(
res.uri,
res.type, // mime type
res.name,
res.size
);
}
} catch (err) {
if (DocumentPicker.isCancel(err)) {
// User cancelled the picker, exit any dialogs or menus and move on
} else {
throw err;
}
}```

In my project. i used another library i.e react-native-open-doc and it not work properly in my project.and i used android studio for found out the error.
you can use this code for find the file in console
try {
const res = await DocumentPicker.pick({
type: [DocumentPicker.types. allFiles],
});
console.log(
res
);
} catch (err) {
if (DocumentPicker.isCancel(err)) {
// User cancelled the picker, exit any dialogs or menus and move on
} else {
throw err;
}
}
}````

Related

React Native Facebook User Photos is Denied

I have a react native app and i can login with facebook. However I can't get the users photo. First of all FB hash key is correct and my app is in live mode. I sent the app to APP REVIEW and the photos are always denied by team and they are telling me they can't get the photos of the users. I use "react-native-fbsdk-next": "^4.3.0" and we use our own api url for photos, not using Graph Api of FB. There is [user_photos] as well beside public_profile. Does anyone know the reason for this ? After I login to Facebook, i try to upload photo via FB and it displays a pop up saying " facebook photos permission is denied. This permission allows your app to read photos of Facebook". Why facebook team denies user photo access ? what else should do to make it work ? My login code implementation is below. I could not find anything on Google regarding this kind of issue. Please help
export const facebookLogin = snackBarBottomMargin => {
return async dispatch => {
try {
const result = await LoginManager.logInWithPermissions([
'public_profile',
'user_photos',
]);
if (!result.isCancelled) {
const data = await AccessToken.getCurrentAccessToken();
if (data && data.accessToken) {
await storage.storeData(
PREFERENCES.FB_ACCESS_TOKEN,
JSON.stringify(data),
);
return data;
} else {
console.log('Facebook result fetch token error cancelled');
return false;
}
} else {
console.log('Login cancelled');
return false;
}
} catch (error) {
dispatch(
showSnackbar(strings.login.facebookLoginError, snackBarBottomMargin),
);
return false;
}
};
};
export function handleFetchFBPhotos(accessToken, after) {
return async dispatch => {
function onSuccess(success) {
dispatch(fetchMediaSuccess(success));
console.log('success', success);
return success;
}
function onError(error) {
dispatch(fetchMediaFailed(error));
console.log('error', error);
return error;
}
try {
dispatch(fetchMediaRequest(true));
const config = {
baseURL: Config.FACEBOOK_BASE_URL,
params: {
type: 'uploaded',
fields: 'images',
after,
},
headers: {Authorization: `Bearer ${accessToken}`},
};
const response = await axios.get(FACEBOOK_PHOTOS, config);
if (response.data && response.data.data) {
console.log('response.data', response.data);
console.log('response.data.data', response.data.data);
console.log('onSuccess(response.data)', onSuccess(response.data));
return onSuccess(response.data);
}
} catch (error) {
const errorObj = getErrorResponse(
error,
Config.FACEBOOK_BASE_URL + FACEBOOK_PHOTOS,
);
console.log('onError(errorObj.message)', onError(errorObj.message));
return onError(errorObj.message);
}
};
}

Permission Denial Error when trying to upload file picked with [react-native-document-picker] to fireStore storage

I'm trying to upload an xlsx to firestore storage ,I'm using react-native-document-picker to pick the file from ExternalStorageDirectoryPath so when just log the files uri I don't get the error but as soon as try to upload the file it throws the error .
relevant code :
const uploadFile=async ()=>{
try {
const res = await DocumentPicker.pick({
type: [DocumentPicker.types.allFiles],
});
const task = Storage().ref('catalogue/'+ res.name).putFile(res.uri);
task.on('state_changed',
sn =>{},
err=>console.log(err),
() => {
console.log('excel uploaded!'+res.name)
Storage()
.ref("catalogue").child(res.name).getDownloadURL()
.then(url => {
console.log('uploaded excel url', url);
}).catch(err=>console.log(err))
}
)
await task
} catch (err) {
if (DocumentPicker.isCancel(err)) {
// User cancelled the picker, exit any dialogs or menus and move on
} else {
throw err;
}
}
}
`
I already included the required permissions in my AndroidManifest.xml file and rebuilt the project
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
but still I'm getting this error :
Permission Denial: reading com.android.externalStorageProvider uri content://com... requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()
I had a similar problem with the frameworks Qt with the last android SDK version, I've fixed the problem by adding requestLegacyExternalStorage in the manifest (pat Application):
<application android:requestLegacyExternalStorage="true" android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" //...
it's related to a recent change in the permission system:
https://developer.android.com/about/versions/11/privacy/storage
Here is my code that solved this issue:
handleFileSelection=async(props)=>
{
try
{
const response = await DocumentPicker.pickMultiple({
presentationStyle: 'fullScreen',
allowMultiSelection: true,
copyTo: 'cachesDirectory',
});
await this.pickImageAndUpload(response[0].fileCopyUri)
} catch (err) {console.warn(err)}
}
pickImageAndUpload = async(uri) => {
const uploadTask = storage().ref().child(`/usersChatImages/${Date.now()}`).putFile(uri)
uploadTask.on('state_changed',
(snapshot) => {
var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
},(error) => { alert("error uploading image")},() => {
uploadTask.snapshot.ref.getDownloadURL().then((downloadURL) =>
{
alert(downloadURL)
}).catch((err)=>{alert("YESSS")}); });
}

Why expo background location stop sending location after 5 min?

I defined the task in App.js, everthing works fine! but after 5 min it stops sending the location, I dont know why.
I'm using this package: https://docs.expo.io/versions/latest/sdk/location/#background-location-methods
TaskManager.defineTask(LOCATION_TASK_NAME, async ({ data, error }) => {
console.log("Esta entrando al task")
if (error) {
console.log(error)
// Error occurred - check `error.message` for more details.
return;
}
if (data) {
const { locations } = data;
let getLastTime = await AsyncStorage.getItem('lastTime');
if(getLastTime){
let timeInterval = moment(new Date()).diff(getLastTime,'seconds')
if(timeInterval<=10) {
return
}
}
await LocationAPI.sendCurrentLocation(locations[0].coords).then(async res=>{
await AsyncStorage.setItem('lastTime', new Date().toString())
}).catch(err=>{
console.log(err)
console.log("en el task")
})
// do something with the locations captured in the background
}
});

js-IPFS / vue.js upload error - Object is not async iterable

I have been working on js-ipfs (0.49.0) and this was working fine but I started getting some issues, anyway I have finally come back to look at the code again and the connection works fine but when I attempt to upload I get a new error
Object is not async iterable
I am not sure what that means or how to address in my code a lot of the examples are for react and not vue
Any pointers much appiciated.
methods: {
async getIpfsNodeInfo() {
try {
// Await for ipfs node instance.
node = await ipfs
// console.log(node)
// Call ipfs `id` method.
// Returns the identity of the Peer.
const { agentVersion, id } = await node.id()
this.agentVersion = agentVersion
this.id = id
// Set successful status text.
this.status = 'Connected to IPFS 😊'
} catch (err) {
// Set error status text.
this.status = `Error: ${err}`
}
},
onFileSelected(event) {
this.selectedFile = event.target.files[0]
this.saveIPFS()
},
async saveIPFS() {
try {
for await (const result of node.add(this.selectedFile)) {
this.fileContents = result
this.getIPFS()
}
} catch (err) {
// Set error status text.
this.status = `Error: ${err}`
}
},
ipfs.add returns a single object since ipfs#0.48.0 - you need to change:
async saveIPFS() {
try {
for await (const result of node.add(this.selectedFile)) {
this.fileContents = result
this.getIPFS()
}
} catch (err) {
// Set error status text.
this.status = `Error: ${err}`
}
},
to:
async saveIPFS() {
try {
this.fileContents = await node.add(this.selectedFile)
this.getIPFS()
} catch (err) {
// Set error status text.
this.status = `Error: ${err}`
}
},
See the blog post for more: https://blog.ipfs.io/2020-07-20-js-ipfs-0-48/#ipfs-add

How can i read the content of a csv file with papaparse ? using react native

I tried papaparse in order to convert a csv file to json , my problem is that he didn't get the content of the file , it return the uri of file as a string .. Here is my code
const chooseFile = async() => {
try {
const`enter code here` res = await DocumentPicker.pick({
type: [DocumentPicker.types.allFiles],
});
Papa.parse(res.uri, {
complete: function(results) {
console.log("Finished:", results.data);
}
}
)
console.log(
res.uri,
res.type, // mime type
res.name,
res.size
);
} catch (err) {
if (DocumentPicker.isCancel(err)) {
// User cancelled the picker, exit any dialogs or menus and move on
} else {
throw err;
}
}
}