Comments (3)
Can you try the example app in the example
folder of this repo? That'll tell us whether the problem is with the plugin, or with your code. If the example app works, feel free to share your code. If it doesn't, please share your device details.
Additionally, empty albums don't show up in Android galleries due to Android limitations, even though they show up in getAlbums()
calls, so that's normal.
from media.
Hell @nkalupahana
I have tested the example app, first of all, there are missing some properties for some tags which didn't let me run ionic cap sync.
Second of all, '@capacitor-community/media": "file:../",'
did not work for me.
After fixing these issues I got the app to run on my phone. I must say it works pretty well & saves Photos correctly to the Demo Album.
This would be my download function, I know its not pretty, since its not yet finalized:
onDownload() {
// Show loading screen
this.loadingController.create({
message: 'Bitte warten…'
}).then(value => {
this.loading = value;
void this.loading.present();
});
const albumName = 'HUBERBAU';
let albumIdentifier = ''
Camera.checkPermissions().then(r => {
if(r.photos === 'granted') {
Media.getAlbums().then(albums => {
console.log(albums)
let appAlbum = albums.albums.find(album => album.name == albumName)
console.log(appAlbum)
if(appAlbum) {
albumIdentifier = appAlbum.identifier
}
})
if(albumIdentifier == '') {
void Media.createAlbum({name: albumName})
Media.getAlbums().then(albums => {
albumIdentifier = albums.albums.find(album => album.name == albumName)?.identifier ?? ''
console.log(albumIdentifier)
})
}
Media.savePhoto({path: this.imageUrl, albumIdentifier: albumIdentifier})
.then(() => {
this.loading?.dismiss();
this.toastController.create({
message: 'Das Foto wurde in das Album \"' + albumName + '\" gespeichert.',
duration: 2000,
color: 'success'
})
.then(toast => toast.present());
})
.catch(reason => {
console.error(reason);
this.loading?.dismiss();
this.toastController.create({
message: albumIdentifier,
duration: 2000,
color: 'danger'
}).then(toast => toast.present());
});
}
});
}
Also btw i am using Angular and not react. Are there maybe some differences?
from media.
Update
I solved it. Basically I was missing async and awaits.. that's why probably the albumIdentifier was empty or the album was not yet created.
My updated code + extraction:
async onDownload() {
// Show loading screen
this.loadingController.create({
message: 'Bitte warten…'
}).then(value => {
this.loading = value;
void this.loading.present();
});
const albumName = 'HUBERBAU';
let appAlbum: MediaAlbum | undefined = undefined
//check if access to photos is granted
await Camera.checkPermissions().then(r => {
if(r.photos !== 'granted') {
Camera.requestPermissions({permissions: ['photos']})
}
});
appAlbum = await this.returnAppAlbumIfExits(albumName)
if(appAlbum === undefined) {
await this.createAppAlbum(albumName)
appAlbum = await this.returnAppAlbumIfExits(albumName)
}
Media.savePhoto({path: this.imageUrl, albumIdentifier: appAlbum?.identifier})
.then(() => {
this.loading?.dismiss();
this.toastController.create({
message: 'Das Foto wurde in das Album \"' + albumName + '\" gespeichert.',
duration: 2000,
color: 'success'
})
.then(toast => toast.present());
})
.catch(reason => {
console.error(reason);
this.loading?.dismiss();
this.toastController.create({
message: appAlbum?.name,
duration: 2000,
color: 'danger'
}).then(toast => toast.present());
});
}
async returnAppAlbumIfExits(name: string) {
const albums = await Media.getAlbums()
return albums.albums.find(album => album.name === name)
}
async createAppAlbum(name: string) {
void Media.createAlbum({name: name})
}
```
from media.
Related Issues (20)
- Read file path from platform-specific identifier on iOS HOT 1
- docs(android): make it clear that file return on savePhoto is only available on Android
- App crash after downloading an image HOT 8
- App is crashed on Android due to EACCES (Permission denied) HOT 11
- Is there any method to retrieve more photos like using offset in query? HOT 1
- feat(android): add getAlbumsPath() function to get where albums are stored on filesystem
- Error: RuntimeException occurred : In SaveVideo method HOT 1
- READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE are still required in Android 13 HOT 5
- RuntimeException occurred / EACCES (Permission denied) when trying to save a photo/gif/video on android < 13 HOT 12
- feat(ios): support jpeg files instead of png HOT 3
- Camera plugin is not implement on Android (Capacitor Camera) when pairing with Capacitor-Community/Media HOT 2
- savePhoto is not working in android 8.1.0 Samsung SM-T580 tablet HOT 1
- MediaFetchOptions support individual photo for high resolution HOT 2
- feat(ios): get specific media by identifier HOT 9
- feat: has access right / error codes for all errors HOT 5
- feat: Capacitor 6 Support HOT 4
- Failed to parse source map HOT 1
- Capacitor 5 - iOS savePhoto from public/images file HOT 2
- Photo Gallery Sync HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from media.