Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
documentPicker(){
DocumentPicker.show({
filetype: [DocumentPickerUtil.allFiles()],
},(error,response) => {
if(Platform.OS === 'ios'){
var ext = response.fileName.split('.')[1].toLowerCase();
var type = this.getMimeType(ext);
}
var file = {
name: response.fileName,
type: Platform.OS === "android" ? response.type : type,
uri: Platform.OS === "android" ? response.uri : response.uri.replace("file://",""),
}
this.setState({ mediaMsg: file });
});
}
documentPicker(){
DocumentPicker.show({
filetype: [DocumentPickerUtil.allFiles()],
},(error,response) => {
if(Platform.OS === 'ios'){
var ext = response.fileName.split('.')[1].toLowerCase();
var type = this.getMimeType(ext);
}
var file = {
name: response.fileName,
type: Platform.OS === "android" ? response.type : type,
uri: Platform.OS === "android" ? response.uri : response.uri.replace("file://",""),
}
this.setState({ mediaMsg: file });
});
}
handleUploadPressed = () => {
DocumentPicker.show(
{
filetype: [DocumentPickerUtil.allFiles()],
},
(error, res) => {
if (!error) {
//console.log(res);
}
}
);
};
restoreBackup = () => {
DocumentPicker.show(
{
filetype: [
Platform.OS === 'android' ? 'application/zip' : 'public.zip-archive',
],
},
(error, res) => {
if (res) {
this.props.saveFileToAppDirectory(res)
} else {
//TODO handle else
console.log('err', error)
}
}
)
}
browseFiles () {
DocumentPicker.show({
filetype: [(Platform.OS === 'android') ? '*/*' : 'public.data']
}, (err, response) => {
if (err) {
console.error(err)
}
const fileDetails = {
uri: response.uri,
name: response.fileName,
size: response.fileSize,
type: response.type
}
this.setState({
...this.state,
fileDetails: fileDetails
})
})
openFilePicker = async () => {
await this.setState({
is_picking_file: true
});
DocumentPicker.show({
filetype: [DocumentPickerUtil.allFiles()],
}, async (err, file) => {
if (!err) {
try {
const file_type = mime.contentType(file.fileName);
const base64 = await RNFS.readFile(file.uri, "base64");
const file_blob = await Blob.build(base64, { type: `${file_type};BASE64` });
this.attachment = {
file_blob: file_blob,
file_name: file.fileName,
file_type: file_type
};