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

[Bug]: Unable to download octet stream using the built-in download function #30285

Open
1 task done
LagunaElectric opened this issue Jan 12, 2024 · 3 comments
Open
1 task done
Assignees
Labels
Bug Something isn't working Community Reported issues reported by community members Framework Functions Cases related to internal functions like showAlert(), navigateTo() etc... High This issue blocks a user from building or impacts a lot of users Javascript Product Issues related to users writing javascript in appsmith Needs Triaging Needs attention from maintainers to triage Production Query & JS Pod Issues related to the query & JS Pod

Comments

@LagunaElectric
Copy link

LagunaElectric commented Jan 12, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Description

A users API returns an image as a binary octet stream. When you try downloading the stream with the following code snippet you get a corrupted file.

async download() {
  let blob = new Blob([FilePicker1.files[0].data], {type: "application/octet-stream"})
  let image = URL.createObjectURL(blob)
  await download(image, 'sample.png', 'image/png')
}

Here I've asked the user for a sample output from their API and uploaded that as a file to the Filepicker widget. You can find the sample in the attached Zendesk thread.

Steps To Reproduce

  1. D&D a Filepicker widget and set the file type to binary.
  2. Upload the file provided by the user to a Filepicker widget. You may need to ensure the file is saved as binary before uploading.
    a. Note: Any octet stream should do. It doesn't have to be the users output.
  3. Add the above function to a JS Object and run it.
  4. Observe that the downloaded file will not open properly.

Environment

Production

ZD Thread

Ticket 1295

Version

Cloud 1.9.59-SNAPSHOT

@LagunaElectric LagunaElectric added Bug Something isn't working Low An issue that is neither critical nor breaks a user flow Needs Triaging Needs attention from maintainers to triage Javascript Product Issues related to users writing javascript in appsmith Framework Functions Cases related to internal functions like showAlert(), navigateTo() etc... labels Jan 12, 2024
@Nikhil-Nandagopal Nikhil-Nandagopal added High This issue blocks a user from building or impacts a lot of users and removed Low An issue that is neither critical nor breaks a user flow labels Jan 17, 2024
@arunvjn
Copy link
Contributor

arunvjn commented Jan 17, 2024

Could you please try the following snippet instead ? @LagunaElectric

async downloadImage() {
  await download(FilePicker1.files[0].data, 'sample.png', 'image/png')
}

@LagunaElectric
Copy link
Author

@arunvjn That gives the same result, downloaded file is corrupt and can't be opened.

@ollcp
Copy link

ollcp commented Mar 26, 2024

import external js library ky , thanks for sindresorhus

export default {

	DownloadBinary: async () => {

		let result = await ky.post("http://x.x.x.x/download",{});
		let buffer = await result.arrayBuffer();

		const blob = new Blob([buffer], {type: 'application/octet-stream'});
		const data = URL.createObjectURL(blob);
		await download(data, "sample.pdf","application/octet-stream")
	}

}

@LagunaElectric

@Nikhil-Nandagopal Nikhil-Nandagopal added the Community Reported issues reported by community members label Apr 18, 2024
@Nikhil-Nandagopal Nikhil-Nandagopal added the Query & JS Pod Issues related to the query & JS Pod label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Community Reported issues reported by community members Framework Functions Cases related to internal functions like showAlert(), navigateTo() etc... High This issue blocks a user from building or impacts a lot of users Javascript Product Issues related to users writing javascript in appsmith Needs Triaging Needs attention from maintainers to triage Production Query & JS Pod Issues related to the query & JS Pod
Projects
None yet
Development

No branches or pull requests

7 participants