apache / apache/cordova-plugin-camera

Empty filename (.Pic.) when selecting image from gallery causes invalid file path and unable to differentiate multiple images because of the same name

Open
#640 0 comments 2 reactions 0 assignees View on GitHub
platform: android
Dominant language
Objective-C
Stars
976
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

# Bug Report

## Problem
Empty filename (.Pic.) causes invalid file path and unable to differentiate multiple images because of the same name
### What is expected to happen?

There should be different filenames for multiple files

### What does actually happen?

It renames every empty filename to .Pic.jpg to every file selected from the gallery but then its complicated to differ this images as there are multiple images with same name.

NOTE:- updating cameraLauncher.java file from renaming empty filename to timestamp works for me , instead of (.Pic.)

## Information

Select image from gallery ,
store its path then select another image then the previously selected image will be lost.

### Command or Code

await this.camera.getPicture(this.options).then(async (imageData) => {
this.errorFlag['imageError'] = false;
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
// let base64Image = 'data:image/jpeg;base64,' + imageData;
//this.imgSrc = this.sanitizer.bypassSecurityTrustUrl("data:Image/*;base64," + imageData);
// let paths = await this.filePath.resolveNativePath(imageData);
console.log("imageData",imageData);
if(imageData.includes("?")){
imageData.split("?")[0];
let fileName = imageData.split("?")[0].split('/').pop();
let path = imageData.split("?")[0].substring(0, imageData.split("?")[0].lastIndexOf("/") + 1);
this.file.readAsDataURL(path, fileName)
.then(base64File => {
this.imagesArray.push(base64File);
this.imagePathArray.push(imageData);
})
.catch(() => {
console.log('Error reading file');
})
}
});

### Environment, Platform, Device

android 10 (samsung M30s)

### Version information

## Checklist

- [x ] I searched for existing GitHub issues
- [x ] I updated all Cordova tooling to most recent version
- [x ] I included all the necessary information above

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.