In this lecture, we're going to decode the base 64 string into binary data in the resource section
of this lecture, I provide a link to a crate called Base64.
It's a simple crate for encoding and decoding base64 values.
We're going to use it to convert the string back into binary data.
First, let's copy the installation code from the documentation page.
Next, open the cargo configuration file.
We level the dependencies table paste in the installation code.
Lastly, let's use it in our project or when the library file.
At the top of the file, we're going to import a function called Base 64 decode.
The decode function will convert a base 64 value into a vector.
Let's use it in our function.
Before we do, I'm not interested in logging the file anymore lets you place the encoded file argument
with a string that says the following Grayscale called.
Next, let's begin decoding the value.
We're going to store the binary data in a variable called base 64 two vector.
The value for this variable will be the decode function with the encoded file argument passed in.
If we hover our mouse over this function will be given more information about the type of value returned
by this function.
It's going to produce a result type.
A few lectures ago, we talked about this type.
Decoding a file can potentially cause an error for demonstration purposes.
We're going to assume the file can be decoded.
We'll change the unwrap function to grab the results.
We should check the type of value wrapped by a resort type, according to the editor.
The type for the successful result will be a vector with a collection of UAH values.
The U8 type is a type for a numbers.
The letter u stands for.
Unsigned, unsigned numbers are always positive.
Binary data is always positive.
We don't need to store negative numbers.
Let's log a message to let us know the value was decoded below the variable called the log function
with the following message.
Image decoded.
Next, let's try uploading an image, open the console in the browser.
After doing so, upload an image.
And the council will find two logs our robust application is telling us the greyscale function has been
called and the image has been decoded.
Awesome.
We can start to load the image.
Let's take care of this step in the next lecture.