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

Downloaded file is corrupted #34

Open
nirmalkumardv opened this issue Sep 26, 2016 · 2 comments
Open

Downloaded file is corrupted #34

nirmalkumardv opened this issue Sep 26, 2016 · 2 comments

Comments

@nirmalkumardv
Copy link

Hi,
I have a scenario, where we need to support to download any kind of file types.
By using angular-file-saver I was able to achieve this, but the downloaded file is always corrupted.
am using 'data:octet/stream;base64'.

Here is my code:

var data = new this.blob([this.studentDocument.documentImage], { type: 'octet/stream;base64' });

this.fileSaver.saveAs(data, this.studentDocument.originalFileName);

The same is working if we use href's "download" attribute like below.

But as IE & Edge browsers do not support this "download" attribute, I cannot use this.

$(invisibleLink)
.attr("href", "data:octet/stream;base64," + this.studentDocument.documentImage)
.attr("download", this.studentDocument.originalFileName);
document.body.appendChild(invisibleLink);

invisibleLink.click();

Has anybody has faced this issue?

Thanks
Nirmal

@ghost
Copy link

ghost commented May 1, 2017

Same problem here. Data returned from API is correct, but when downloaded through angular-file-saver it's corrupted.

@ghost
Copy link

ghost commented May 1, 2017

I fixed it:

		$http({
				method: 'GET',
				url: API + "/certificates/" + item.documents_id,
				responseType: "arraybuffer",
			})
			.then(function(resp) {
				var data = new Blob([resp.data], {
					type: 'application/x-pkcs12'
				});
				if (item.doc_descr) {
					FileSaver.saveAs(data, item.doc_descr + '.p12');
				} else if (item.reader_name) {
					FileSaver.saveAs(data, item.reader_name + '.p12');
				}
			}).catch(function(error) {
				console.log("Failed!");
				console.log("Error " + error);
			});

I added the header: responseType: "arraybuffer"

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

1 participant