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

Buffer undefined in Preview.vue #120

Open
kmx2 opened this issue Apr 30, 2022 · 2 comments
Open

Buffer undefined in Preview.vue #120

kmx2 opened this issue Apr 30, 2022 · 2 comments

Comments

@kmx2
Copy link

kmx2 commented Apr 30, 2022

this is code in preview.vue

loadImage() {
// if authorization required
if (this.auth) {
GET.preview(
this.selectedDisk,
this.selectedItem.path,
).then((response) => {
const mimeType = response.headers['content-type'].toLowerCase();
const imgBase64 = Buffer.from(response.data, 'binary').toString('base64');

      this.imgSrc = `data:${mimeType};base64,${imgBase64}`;
    });

.....

error:
Uncaught (in promise) ReferenceError: Buffer is not defined
at eval (Preview.vue?ae5e:134:1)

Buffer.from is a node.js type ???

@RobinHossain
Copy link

Hi @alexusmai

I am having the same the isssue. Would you please review that?

Thanks!

@RobinHossain
Copy link

An alernative option to Buffer.from for the "components/modals/views/PreviewModal.vue" page which works fine in my case.

--- const imgBase64 = Buffer.from(response.data, 'binary').toString('base64');
+++ const imgBase64 = this._arrayBufferToBase64(response.data);

Add the following function at method

_arrayBufferToBase64( buffer ) {
            let binary = '';
            const bytes = new Uint8Array( buffer );
            const len = bytes.byteLength;
            for (var i = 0; i < len; i++) {
                binary += String.fromCharCode( bytes[ i ] );
            }
            return window.btoa( binary );
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants