I am using crates Rocket and base64 and I'm trying to decode base64 from an upload, but somewhere in the process the base64 is not serializing or deserializing correction. I have identified that at least the "+" character is being converted to a space, no idea what else may not be handled correctly and I don't know how to trace the bug. Any help???
In javascript I get identical results from the first and last logs and the middle is the correct plain text, where item is a text file from an upload field:
console.log("orig: ",item);
console.log("eURI: ",atob(encodeURI(item)));
console.log("from eURI: ",btoa(atob(encodeURI(item))))
I have a struct:
#[derive(Serialize)]
#[derive(FromForm,Debug)]
pub struct NewArticle{
pub content:String,
}
This is the relevant function
#[post("/upload", data="<form>")]
pub fn receive_post(form: Form<NewArticle>){
let test = form.into_inner();
let resp = NewArticle::from(test);
println!("{:?}",resp.content);
let decoded = base64::decode_config(&resp.content, base64::URL_SAFE).unwrap();
println!("{:?}",decoded);
}
This is the error I receive:
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidByte(19, 32)',
I have both done a println!("{:?}",item) as well as sent the string back to the browser and output it in console.log with no attempt at base64 and that's where I see the character that's been converted. The first " " instead of "+" occurs at the 19th character.