mirror of
https://github.com/fluencelabs/examples
synced 2025-06-26 16:21:36 +00:00
upload & download works
This commit is contained in:
@ -17,7 +17,7 @@
|
||||
use std::fs;
|
||||
use fluence::fce;
|
||||
use fluence::WasmLoggerBuilder;
|
||||
use std::path::PathBuf;
|
||||
use std::path::Path;
|
||||
|
||||
const SITES_DIR: &str = "/sites/";
|
||||
|
||||
@ -28,14 +28,14 @@ pub fn main() {
|
||||
|
||||
/// You can read or write files from the file system if there is permission to use directories described in `Config.toml`.
|
||||
#[fce]
|
||||
pub fn put(name: String, file_content: Vec<u8>) -> String {
|
||||
log::info!("put called with file name {}", name);
|
||||
pub fn put(file_name: String, file_content: Vec<u8>) -> String {
|
||||
log::info!("put called with file name {}", file_name);
|
||||
|
||||
let rpc_tmp_filepath = format!("{}{}", SITES_DIR, name);
|
||||
let path = Path::new(SITES_DIR).join(file_name);
|
||||
|
||||
let result = fs::write(PathBuf::from(rpc_tmp_filepath.clone()), file_content);
|
||||
let result = fs::write(&path, file_content);
|
||||
if let Err(e) = result {
|
||||
return format!("file can't be written: {}", e);
|
||||
return format!("file {} can't be written: {}", path.to_string_lossy(), e);
|
||||
}
|
||||
|
||||
String::from("Ok")
|
||||
@ -45,7 +45,7 @@ pub fn put(name: String, file_content: Vec<u8>) -> String {
|
||||
pub fn get(file_name: String) -> Vec<u8> {
|
||||
log::info!("get called with file name: {}", file_name);
|
||||
|
||||
let tmp_filepath = format!("{}{}", SITES_DIR, file_name);
|
||||
let path = Path::new(SITES_DIR).join(file_name);
|
||||
|
||||
fs::read(tmp_filepath).unwrap_or_else(|_| b"error while reading file".to_vec())
|
||||
fs::read(&path).unwrap_or_else(|err| format!("error while reading file {}: {}", path.to_string_lossy(), err).into_bytes())
|
||||
}
|
||||
|
Reference in New Issue
Block a user