Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Saving video files corrupts them #33

Open
r3plica opened this issue Jun 6, 2022 · 5 comments
Open

Saving video files corrupts them #33

r3plica opened this issue Jun 6, 2022 · 5 comments

Comments

@r3plica
Copy link

r3plica commented Jun 6, 2022

Hey,

So I have added ngx-filesaver to my angular application and it downloads images fine, but with videos it doesn't work properly. I does download the video, but when I try to play it, it says the video is corrupted. I can play the video in the browser (before downloading). The code I have looks like this:

public download(asset: SimpleResourceBase): void {
  const parts = asset.secureUrl.split('.');
  if (parts.length === 1) return;

  const extension = parts[parts.length - 1];

  this.httpClient
    .get<Blob>(asset.secureUrl, {
      observe: 'body',
      responseType: 'blob' as 'json',
    })
    .subscribe((response) => {
      console.log(response);
      this.fileSaverService.save(
        <any>response,
        `${asset.fileName}.${extension}`
      );
    });
}

and the SimpleResourceBase looks like this:

export declare class SimpleResourceBase {
    id: string;
    publicId: string;
    normalisePublicId: string;
    folder: string;
    fileName: string;
    indexUrl: string;
    url: string;
    secureUrl: string;
}

Is there something I have to do differently, to get the video to download?

@cipchk
Copy link
Owner

cipchk commented Jun 6, 2022

Maybe using the wrong type.

- this.fileSaverService.save(<any>response, `${asset.fileName}.${extension}`);
+ this.fileSaverService.save(<any>response, `${asset.fileName}.${extension}`, 'video/mp4');

@r3plica
Copy link
Author

r3plica commented Jun 7, 2022

Nah, it's not the wrong type, in the console.log(response) it shows the correct type, but I did add that and I still got the same issue.

@cipchk
Copy link
Owner

cipchk commented Jun 7, 2022

Can you trying use the save method of file-saver, This helps to tracking the problem, like this:

import { saveAs, FileSaverOptions } from 'file-saver';

saveAs(response)

@r3plica
Copy link
Author

r3plica commented Jun 7, 2022

I updated my download method to this:

public download(asset: SimpleResourceBase): void {
  const parts = asset.secureUrl.split('.');
  if (parts.length === 1) return;

  const extension = parts[parts.length - 1];

  this.httpClient
    .get<Blob>(asset.secureUrl, {
      observe: 'body',
      responseType: 'blob' as 'json',
    })
    .subscribe((response) => {
      console.log(response);
      // this.fileSaverService.save(
      //   <any>response,
      //   `${this.getFilename(asset.fileName)}.${extension}`
      // );
      saveAs(response, `${this.getFilename(asset.fileName)}.${extension}`);
    });
}

And it still does the same thing:

image

And when I open it, it doesn't play

@cipchk
Copy link
Owner

cipchk commented Jun 7, 2022

Sorry, This looks like an issue with filesaver.js.

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

No branches or pull requests

2 participants