Skip to content

Instantly share code, notes, and snippets.

@peterbsmyth
Created February 6, 2018 14:12
Show Gist options
  • Save peterbsmyth/def6d983788bdc55f5219774acecd581 to your computer and use it in GitHub Desktop.
Save peterbsmyth/def6d983788bdc55f5219774acecd581 to your computer and use it in GitHub Desktop.
<StackLayout *ngFor="let photo of state.photos" style="margin: 10">
<Image [src]='photo' height="200"></Image>
</StackLayout>
onSelectMultipleTap() {
const context = imagepicker.create({
mode: 'multiple',
newestFirst: true,
});
this.startSelection(context);
}
startSelection(context) {
context
.authorize()
.then(() => {
this.state.photos = [];
return context.present();
})
.then((selection) => {
selection.forEach((selected) => {
selected.getImage()
.then((imagesource) => {
const folder = fs.knownFolders.documents();
const path = fs.path.join(folder.path, 'Test.png');
imagesource.saveToFile(path, 'png');
});
});
// array for all saved selected photos
const fileUris = [];
selection.forEach((element) => {
// element.fileUri brings back the path with file:// at the beginning of the path
const newPath = element.fileUri.slice(7);
// create array with just new photo paths
fileUris.push(newPath);
});
this.state.photos = fileUris;
// need to get each path to save to the correct photo # in the form...
fileUris.forEach((path, i) => {
const num = 6 - i;
this.form.controls['photo' + num.toString()].patchValue(path);
});
}).catch(function (e) {
console.log(e);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment