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

How can i get the cropped file? #272

Open
AmirGilboa opened this issue Dec 6, 2017 · 2 comments
Open

How can i get the cropped file? #272

AmirGilboa opened this issue Dec 6, 2017 · 2 comments

Comments

@AmirGilboa
Copy link

in order to use ng2-file-upload to upload the cropped image to server, i need to get hold of the cropped image, and convert it to javascript File object. Any tip on how to do that?

@webcoderr
Copy link

You can take the cropped image from this.data.image. This will give you the base 64, then you can convert it to blob and then to a file.

@Nervniyak
Copy link

I used this code from SO to convert

private convertImageUriToFile(uri: string) {
    const arr = uri.split(',');
    const mime = arr[0].match(/:(.*?);/)[1];
    const bstr = atob(arr[1]);
    let n = bstr.length;
    const u8arr = new Uint8Array(n);
    while (n--) {
      u8arr[n] = bstr.charCodeAt(n);
    }
    return new File([u8arr], this.fileName, { type: mime });
  }

Which I call with .image property
this.convertImageUriToFile(this.imageData.image

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

3 participants