pub fn encode_path(path: &str) -> String
Expand description
Encodes a file path for safe use in URLs
Files.com paths may contain special characters (spaces, brackets, unicode, etc.) that need to be properly URL-encoded. This function:
- Splits the path by
/
to preserve directory structure - Percent-encodes each path segment individually (using %20 for spaces, not +)
- Rejoins with
/
separators
§Arguments
path
- The file or folder path to encode
§Returns
A URL-safe encoded path string
§Examples
use files_sdk::utils::encode_path;
assert_eq!(encode_path("/my folder/file.txt"), "/my%20folder/file.txt");
assert_eq!(encode_path("/data/file[2024].txt"), "/data/file%5B2024%5D.txt");
assert_eq!(encode_path("/文档/файл.txt"), "/%E6%96%87%E6%A1%A3/%D1%84%D0%B0%D0%B9%D0%BB.txt");