Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: while i am taking picture using capacitor camera after taking picture my app is restart #6929

Closed
PYTHAVA opened this issue Sep 22, 2023 · 3 comments

Comments

@PYTHAVA
Copy link

PYTHAVA commented Sep 22, 2023

Bug Report

Capacitor Version

  "@capacitor/camera": "^4.1.4",
    "@capacitor/core": "^4.5.0",

Platform(s)

Platform: android
Needs: reply please

Current Behavior

after taking image my app restart not upload the image on the server

Expected Behavior

after taking image will be upload on the server

Code Reproduction

const handleFileUpload = async (file, name) => {
try {
const requestOptions = {
method: 'POST',
headers: {
'Content-type': 'images/JPEG',
'Authorization': 'Bearer ' + t,
'Accept': '/'
},
body: file
};

  const url = baseURL + '/rest/files?name=' + name;

  const response = await fetch(url, requestOptions);
  if (!response.ok) {
    throw new Error('Failed to upload file');
  }

  const data = await response.json();
  setFileName(data.fileRef);
  setShowLoading(false);
} catch (error) {
  console.error(error);
}

};

function b64toBlob(b64Data, contentType) {
contentType = contentType || '';
var sliceSize = 512;
var byteCharacters = atob(b64Data);
var byteArrays = [];

for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
  var slice = byteCharacters.slice(offset, offset + sliceSize);
  var byteNumbers = new Array(slice.length);
  for (var i = 0; i < slice.length; i++) {
    byteNumbers[i] = slice.charCodeAt(i);
  }
  var byteArray = new Uint8Array(byteNumbers);
  byteArrays.push(byteArray);
}

var blob = new Blob(byteArrays, { type: contentType });
return blob;

}
const handleClickImage = async () => {
const image = await Camera.getPhoto({
quality: 90,
allowEditing: false,
resultType: CameraResultType.Base64
});
const fileName = (new Date().valueOf() + '.jpeg');
const blob = b64toBlob(image.base64String, 'image/jpeg');
setShowLoading(true)
handleFileUpload(blob, fileName);
};

Other Technical Details

npm --version output:
'ALPACA-CP': '0.0.1',
npm: '8.19.2',
node: '18.12.1',
v8: '10.2.154.15-node.12',
uv: '1.43.0',
zlib: '1.2.11',
brotli: '1.0.9',
ares: '1.18.1',
modules: '108',
nghttp2: '1.47.0',
napi: '8',
llhttp: '6.0.10',
openssl: '3.0.7+quic',
cldr: '41.0',
icu: '71.1',
tz: '2022b',
unicode: '14.0',
ngtcp2: '0.8.1',
nghttp3: '0.7.0'
}
node --version output:

pod --version output (iOS issues only):

Additional Context

@PYTHAVA
Copy link
Author

PYTHAVA commented Sep 23, 2023

please help me solve this essue

@jcesarmobile
Copy link
Member

closing as duplicate of ionic-team/capacitor-plugins#1736

@jcesarmobile jcesarmobile closed this as not planned Won't fix, can't repro, duplicate, stale Sep 25, 2023
@ionitron-bot
Copy link

ionitron-bot bot commented Oct 25, 2023

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Oct 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants