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

browser platform: saveImage and saveVideo should download file #38

Open
viskin opened this issue Feb 18, 2017 · 1 comment
Open

browser platform: saveImage and saveVideo should download file #38

viskin opened this issue Feb 18, 2017 · 1 comment

Comments

@viskin
Copy link
Member

viskin commented Feb 18, 2017

No description provided.

@wobsoriano
Copy link

Here's what I did:

Check what platform it is, if it's running in a browser, download the file using this function:

export function downloadImageFromUrl(url, filename) {
  const canvas = document.createElement('canvas');
  const ctx = canvas.getContext('2d');
  const img = new Image();
  img.crossOrigin = '';
  img.src = url;
  img.onload = function () {
    const img = this;
    canvas.width = img.width;
    canvas.height = img.height;
    ctx.drawImage(img, 0, 0, img.width, img.height);

    // Create hidden href
    const a = document.createElement('a');
    a.href = canvas.toDataURL();
    a.download = filename || `${Date.now()}.jpeg`;
    document.body.appendChild(a);
    a.click();
  };
}

I'm using this to download firebase storage files.

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

No branches or pull requests

2 participants