Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async componentDidMount() {
if (Platform.OS === 'web') {
return;
}
const { status } = await Permissions.askAsync(Permissions.CAMERA);
this.setState({ permission: status, permissionsGranted: status === 'granted' });
try {
await FileSystem.makeDirectoryAsync(FileSystem.documentDirectory + 'photos');
} catch (error) {
// tslint:disable-next-line no-console
console.log(error, 'Directory exists');
}
}
function handleGetFileInfo () {
console.log('getFileInfo')
// FileSystem.readDirectoryAsync(FileSystem.documentDirectory).then(res => console.log(res))
getFileInfo({filePath: FileSystem.documentDirectory + 'logo-taro.png'})
.then(res => console.log(res))
.catch(e => console.log('error', e))
}
import * as FileSystem from 'expo-file-system';
export const DocumentDir = FileSystem.documentDirectory;
export const CacheDir = FileSystem.cacheDirectory;
const resolvePath = (...paths) => paths.join('/').split('/').filter(part => part && part !== '.').join('/');
// Wrap function to support both Promise and callback
async function withCallback(callback, func) {
try {
const result = await func();
if (callback) {
callback(null, result);
}
return result;
} catch (err) {
if (callback) {
callback(err);
} else {
submit = async() => {
const { text, certificate } = this.state;
const { connectServer } = this.props;
let cert = null;
if (certificate) {
const certificatePath = `${ FileSystem.documentDirectory }/${ certificate.name }`;
try {
await FileSystem.copyAsync({ from: certificate.path, to: certificatePath });
} catch (e) {
log(e);
}
cert = {
path: this.uriToPath(certificatePath), // file:// isn't allowed by obj-C
password: certificate.password
};
}
if (text) {
Keyboard.dismiss();
connectServer(this.completeUrl(text), cert);
}
}
export function getLegacyDocumentDirectoryAndroid() {
if (Platform.OS !== 'android' || FileSystem.documentDirectory == null) {
return null;
}
// expo-file-system decodes paths so we need to encode twice
let id = encodeURIComponent(encodeURIComponent(Constants.manifest.id));
const oldFilesDirectory = `${FileSystem.documentDirectory}ExperienceData/${id}/`;
return oldFilesDirectory;
}
export const noopResolve = async (legacyFile, currentFile) => {
export function getLegacyDocumentDirectoryAndroid() {
if (Platform.OS !== 'android' || FileSystem.documentDirectory == null) {
return null;
}
// expo-file-system decodes paths so we need to encode twice
let id = encodeURIComponent(encodeURIComponent(Constants.manifest.id));
const oldFilesDirectory = `${FileSystem.documentDirectory}ExperienceData/${id}/`;
return oldFilesDirectory;
}
export const noopResolve = async (legacyFile, currentFile) => {
let p = new Promise((resolve, reject) => {
let fileName = url.split('/')
fileName = fileName[fileName.length - 1]
const downloadFileCallback = (res) => {
const {totalBytesWritten, totalBytesExpectedToWrite} = res
let progress = totalBytesWritten / totalBytesExpectedToWrite * 100
progress = Number(progress.toFixed(2))
p.onProgressUpdateCb && p.onProgressUpdateCb({
progress,
totalBytesWritten,
totalBytesExpectedToWrite
})
}
downloadResumable = FileSystem.createDownloadResumable(
url,
filePath || `${FileSystem.documentDirectory}${fileName}`,
{
headers: header
},
downloadFileCallback
)
downloadResumable.downloadAsync().then((resp) => {
const {uri, status} = resp
const res = {
tempFilePath: uri,
statusCode: status
}
success && success(res)
complete && complete(res)
resolve(res)
}).catch((err) => {
import * as ImagePicker from 'expo-image-picker';
import * as FileSystem from 'expo-file-system';
import * as MediaLibrary from 'expo-media-library';
import * as Permissions from 'expo-permissions';
const mediaOptions = {
allowsEditing: true,
quality: 1.0,
allowsMultipleSelection: false,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
exif: false,
base64: false,
};
const directory = `${FileSystem.documentDirectory}/photos`;
async function ensurePermissionsAsync(): Promise {
const { status } = await Permissions.askAsync(Permissions.CAMERA, Permissions.CAMERA_ROLL);
if (status !== Permissions.PermissionStatus.GRANTED) {
alert(
'Cannot select a banner photo without media access! Please enable the "Camera" & "Camera Roll" permission in your system settings.'
);
return false;
}
return true;
}
export async function takePhotoAsync(): Promise {
if (!(await ensurePermissionsAsync())) return null;
const media = await ImagePicker.launchCameraAsync(mediaOptions);
import * as FileSystem from 'expo-file-system';
import * as SecureStore from 'expo-secure-store';
import uuid from './uuid';
import * as AES from './aes';
const storageFileUriKey = 'storage_file_uri';
const storageDirectoryUri = `${FileSystem.documentDirectory}persist-storage/`;
export const createDirectory = () => {
FileSystem.getInfoAsync(storageDirectoryUri)
.then(({ exists }) => {
if (!exists) {
FileSystem.makeDirectoryAsync(storageDirectoryUri, { intermediates: true });
}
});
};
export const getAsync = async (key, secureStoreOptions) => {
return new Promise(async (resolve, reject) => {
try {
let value = null;
const aesKey = await SecureStore.getItemAsync(key, secureStoreOptions);
if (aesKey) {
_startDownloading = async () => {
const url = 'http://ipv4.download.thinkbroadband.com/5MB.zip';
const fileUri = FileSystem.documentDirectory + '5MB.zip';
const callback: FileSystem.DownloadProgressCallback = downloadProgress => {
const progress =
downloadProgress.totalBytesWritten / downloadProgress.totalBytesExpectedToWrite;
this.setState({
downloadProgress: progress,
});
};
const options = { md5: true };
this.download = FileSystem.createDownloadResumable(url, fileUri, options, callback);
try {
await this.download.downloadAsync();
if (this.state.downloadProgress === 1) {
alert('Download complete!');
}
} catch (e) {