Fixed panic when uploading binary file
This commit is contained in:
parent
1078f7fb42
commit
c60e4a51ab
|
@ -103,10 +103,9 @@ impl Variables {
|
|||
|
||||
fn file_string(filename: &str, content_type: Option<&str>, content: &[u8]) -> String {
|
||||
if let Some(content_type) = content_type {
|
||||
format!("file:{}:{}|", filename, content_type)
|
||||
+ unsafe { std::str::from_utf8_unchecked(content) }
|
||||
format!("file:{}:{}|", filename, content_type) + &base64::encode(content)
|
||||
} else {
|
||||
format!("file:{}|", filename) + unsafe { std::str::from_utf8_unchecked(content) }
|
||||
format!("file:{}|", filename) + &base64::encode(content)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,20 +80,22 @@ impl<'a> InputValueType for Upload {
|
|||
let s = &s[5..];
|
||||
if let Some(idx) = s.find('|') {
|
||||
let name_and_type = &s[..idx];
|
||||
let content = &s[idx + 1..];
|
||||
let content_b64 = &s[idx + 1..];
|
||||
if let Some(type_idx) = name_and_type.find(':') {
|
||||
let name = &name_and_type[..type_idx];
|
||||
let mime_type = &name_and_type[type_idx + 1..];
|
||||
let content = base64::decode(content_b64).ok().unwrap_or_default();
|
||||
return Some(Self {
|
||||
filename: name.to_string(),
|
||||
content_type: Some(mime_type.to_string()),
|
||||
content: content.as_bytes().to_vec(),
|
||||
content,
|
||||
});
|
||||
} else {
|
||||
let content = base64::decode(content_b64).ok().unwrap_or_default();
|
||||
return Some(Self {
|
||||
filename: name_and_type.to_string(),
|
||||
content_type: None,
|
||||
content: content.as_bytes().to_vec(),
|
||||
content,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user