Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve) => {
DocumentPicker.show({ filetype: [DocumentPickerUtil.allFiles()] }, (error, res) => {
if (error) {
// Also returns an error if the user doesn't pick a file
// so just resolve with null.
console.info('pickDocument error:', error);
resolve(null);
return;
}
resolve(res);
});
});
}
handleUploadPressed = () => {
DocumentPicker.show(
{
filetype: [DocumentPickerUtil.allFiles()],
},
(error, res) => {
if (!error) {
//console.log(res);
}
}
);
};
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 });
});
}
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
};
Alert.alert("Success", "File attached!");
pickFile = () => {
DocumentPicker.show({ filetype: [DocumentPickerUtil.allFiles()] }, (error, response) => {
if (response) {
this.setState({ content: { objectName: ObjectName.File, local: response.uri } });
}
});
};