Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var fetchParams = {
first: 1000,
groupTypes: groupTypes,
assetType: assetType,
};
if (Platform.OS === "android") {
// not supported in android
delete fetchParams.groupTypes;
}
if (this.state.lastCursor) {
fetchParams.after = this.state.lastCursor;
}
CameraRoll.getPhotos(fetchParams)
.then((data) => this._appendImages(data), (e) => console.log(e));
}
const fetchParams = {
first: 100,
groupTypes,
assetType,
};
if (Platform.OS === 'android') {
// not supported in android
delete fetchParams.groupTypes;
}
if (this.state.lastCursor) {
fetchParams.after = this.state.lastCursor;
}
CameraRoll.getPhotos(fetchParams)
.then(data => this.appendImages(data), e => console.log(e));
}
this.downloadTask = RNFetchBlob.config(options).fetch('GET', imageUrl);
this.downloadTask.progress((received, total) => {
const progress = (received / total) * 100;
if (this.mounted) {
this.setState({
progress,
started: true,
});
}
});
const res = await this.downloadTask;
let path = res.path();
if (saveToCameraRoll) {
path = await CameraRoll.saveToCameraRoll(path, 'photo'); /* eslint-disable-line require-atomic-updates */
}
if (this.mounted) {
this.setState({
progress: 100,
}, async () => {
if (this.state.didCancel) {
try {
await RNFetchBlob.fs.unlink(path);
} finally {
this.downloadDidCancel();
}
} else {
this.props.onDownloadSuccess();
}
});
export async function saveAttachmentToCameraRoll(filePath: string, mimeType: string): Promise {
const fileURL = 'file://' + filePath
const saveType = mimeType.startsWith('video') ? 'video' : 'photo'
const logPrefix = '[saveAttachmentToCameraRoll] '
try {
await requestPermissionsToWrite()
logger.info(logPrefix + `Attempting to save as ${saveType}`)
await CameraRoll.saveToCameraRoll(fileURL, saveType)
logger.info(logPrefix + 'Success')
} catch (e) {
// This can fail if the user backgrounds too quickly, so throw up a local notification
// just in case to get their attention.
PushNotifications.localNotification({
message: `Failed to save ${saveType} to camera roll`,
})
logger.debug(logPrefix + 'failed to save: ' + e)
throw e
} finally {
require('rn-fetch-blob').default.fs.unlink(filePath)
}
}
componentDidMount() {
const fetchParams = {
first: 25,
};
CameraRoll.getPhotos(fetchParams).then((data: any) => {
const assets = data.edges;
const images = assets.map((asset: any) => asset.node.image);
this.setState({
tmpImages: images,
});
const imgArray: any = [];
this.state.tmpImages.forEach(function (image: any, index: number) {
imgArray.push({uri: image.uri, id: index, height: Math.round(Math.random() * 50 + 100)})
});
this.setState({images: imgArray});
}).catch((err: any) => {
console.log("Error retrieving photos");
});
}
componentDidMount(): void {
const fetchParams = {
first: 25,
};
CameraRoll.getPhotos(fetchParams).then((data: any) => {
const assets = data.edges;
const images = assets.map((asset: any) => asset.node.image);
this.setState({
tmpImages: images,
});
const imgArray: any = [];
this.state.tmpImages.forEach(function (image: any, index: number) {
imgArray.push({uri: image.uri, id: index, height: Math.round(Math.random() * 50 + 100)})
});
this.setState({images: imgArray});
this.onBlurViewLoaded.bind(this)
}).catch((err: any) => {
console.log("Error retrieving photos");
});
}
async function getInitalGalleryContents() {
try {
const photos = await CameraRoll.getPhotos({
first: GALLERY_IMAGE_PER_PAGE,
})
setGalleryContents(
photos.edges.map(({ node: { image: { filename, uri }, type: mime } }) => ({
filename: filename || '',
uri,
mimeType: mime,
})),
)
setGalleryImageEndCursor(photos.page_info.has_next_page ? photos.page_info.end_cursor : null)
} catch (err) {
console.log('getPhotos err', err)
}
}
onPress() {
images[currentIndex] &&
CameraRoll.save(images[currentIndex].uri, { type: 'photo' })
.then(() => {
setModalVisibility(false)
handleMessage(t('chat.files.image-saved'))
})
.catch((err) => console.log(err))
},
},
const saveImage = (uri: string) => (
CameraRoll.saveToCameraRoll(uri, 'photo')
)
workId,
workTitle,
workType,
saveImageSettings,
imageIndex || index,
);
try {
const res = await RNFetchBlob.config({
path: `${imagesDir}/${fileName}`,
}).fetch('GET', url, {
referer: 'http://www.pixiv.net',
});
const filePath = res.path();
if (Platform.OS === 'ios') {
try {
await CameraRoll.saveToCameraRoll(filePath);
this.showToast(
i18n.formatString(i18n.saveImageSuccess, fileName),
);
} catch (err) {
this.showToast(i18n.formatString(i18n.saveImageError, fileName));
}
} else if (Platform.OS === 'android') {
this.showToast(i18n.formatString(i18n.saveImageSuccess, fileName));
try {
await RNFetchBlob.fs.scanFile([{ path: filePath }]);
} catch (err) {}
}
} catch (err) {
this.showToast(i18n.formatString(i18n.saveImageError, fileName));
}
});