Skip to content

Commit

Permalink
fixed image data tobase64 method
Browse files Browse the repository at this point in the history
  • Loading branch information
Thombrix committed May 2, 2024
1 parent 0c383c1 commit 82c6289
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions frontend/src/clients/apiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,15 @@ export class ApiClient {
}

static async getPicture(id) {
const arrayBufferToBase64 = buffer =>
btoa(String.fromCharCode(...new Uint8Array(buffer)));
const arrayBufferToBase64 = buffer => {
let binary = '';
const bytes = new Uint8Array(buffer);
const len = bytes.byteLength;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return btoa(binary);
};

try {
const response = await axios.get(
Expand All @@ -235,7 +242,7 @@ export class ApiClient {

return `data:image/jpeg;base64,${arrayBufferToBase64(response.data)}`;
} catch (error) {
console.error(error.response?.data);
console.error(error);
setError(error.response?.data, 'error');
return error;
}
Expand Down

0 comments on commit 82c6289

Please sign in to comment.