Downloading from binary files
By now, we have a few standard ways of encoding text. I downloaded a text webpage, and it got sent to me as bytes, and there are a lot of ways we can represent bytes. One way we can represent bytes is as characters, through an encoding called latin1.
But there are other encodings. Here's a sentence. That looks ugly; maybe it was encoded as something other than latin1. It turns out that it was encoded as UTF A video file is also a series of bytes, but it is not encoded as latin1.
It's also not encoded as utf For example, this video about open data is encoded as WebM. Text files are a binary file where the data are encoded with a text encoding like latin1 or utf-8 rather than webm.
Regardless of its encoding, a file still a series of bytes, and we don't need to know anything about the encoding in order to download a series of bytes; downloading this file is the same as downloading a text file. We could decode the bytes with one of our text decoders, but it will probably look pretty nonsense.
Files are files, even when they're not text that you can read, and even when you're downloading them from the internet. Downloading binary files Binary files might seem scary if you're used to looking at text. Python print response. Bytes as characters It's easy to confuse the two because we often represent bytes as characters when displaying them. If you wanted to output it to a file, you just add -o to the command line with a target file name note: that is a lower case o :.
To download a binary file, we can use the -O parameter which pulls down the content exactly as the source file specified dictates, including the name as such:. We can achieve the same result by using the -o parameter option also and specifying a target filename:. This is handy if you want to change the name of the file on the target filesystem. You can pass along all sorts of variable goodness into the name for output when you want to do something programmatically, which is all sorts of awesome as you get to using cURL for automated file management and other neat functions.
Show 2 more comments. Active Oldest Votes. Jo David Jo David 1, 2 2 gold badges 16 16 silver badges 19 19 bronze badges. Thanks for the answer. But my problem is a bit different. I can download pdfs or images, but when i call the REST service that returns the binary data, i don't know what is the type of the file. You could make another request just before downloading the file to get the fileType and maybe the file name for the UI.
A tiny correction Jo, for a bytearray Brob parameter should be an array. Where the function onDownloaded is defined? Show 3 more comments. Sign up or log in Sign up using Google.
Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.