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

Not working on Safari 13 #574

Open
manduriomane opened this issue Aug 4, 2023 · 3 comments
Open

Not working on Safari 13 #574

manduriomane opened this issue Aug 4, 2023 · 3 comments
Labels

Comments

@manduriomane
Copy link

Hi,

ngx-image-cropper not working on Safari 13.

When I select a file from file input, I receive this error:

TypeError: file.arrayBuffer is not a function. (In 'file.arrayBuffer()', 'file.arrayBuffer()' is undefined)

image

This is my HTML code:

<input type="file" (change)="fileChangeEvent($event)" accept="image/*">

<image-cropper [imageChangedEvent]="imageChangedEvent" [maintainAspectRatio]="true" output="base64"
          [containWithinAspectRatio]="containWithinAspectRatio" [aspectRatio]="imgAspectRatio"
          [resizeToWidth]="imgResizeToWidth" [cropperMinWidth]="imgCropperMinWidth" [onlyScaleDown]="true"
          [roundCropper]="false" [canvasRotation]="canvasRotation" [transform]="transform" [alignImage]="'left'"
          [style.display]="showCropper ? null : 'none'" format="png" (imageCropped)="imageCropped($event)"
          (imageLoaded)="imageLoaded()" (cropperReady)="cropperReady($event)" (loadImageFailed)="loadImageFailed()">
        </image-cropper>

Ts code:

imageChangedEvent: any = '';

fileChangeEvent(event: any): void {
    if (event.target.files.length) {
      this.imageChangedEvent = event;
       this.cdRef.detectChanges();
    }
  }

How I can solve this problem?

Thanks a lot

@manduriomane
Copy link
Author

Hi,

I added this patch and now it works:

using FileReader
(function () {
    File.prototype.arrayBuffer = File.prototype.arrayBuffer || myArrayBuffer;
    Blob.prototype.arrayBuffer = Blob.prototype.arrayBuffer || myArrayBuffer;
    function myArrayBuffer() {
        // this: File or Blob
        return new Promise((resolve) => {
            let fr = new FileReader();
            fr.onload = () => {
                resolve(fr.result);
            };
            fr.readAsArrayBuffer(this);
        })
    }
})();

@Mawi137
Copy link
Owner

Mawi137 commented Sep 2, 2023

Hi

Thanks, I'll see if I can add this to the lib as well so Safari 13 is still supported.

Copy link

stale bot commented Dec 15, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
@Mawi137 @manduriomane and others