Support for File
Currently, Lum supports communication over JSON only. But in real life, we need to upload files and also download files from Server. So we will bring that support
Tasks -
- [x] **Send File To Client: ** Any function can return an instance of a file from any function. In the backend, we need to check the return type and if that is file, need to set the appropriate headers and send the file
- [ ] Receive File From Client: : To start work on this feature set, we need to first complete this issue #8 . After then we can work on this. When the file will receive we will cast it to file and pass it to function
@Tanmoy741127 , about your first point: would it be possible to use Path objects to serve files/folders to the user? I imagine something like this would be useful:
from pathlib import Path
def get_file(name) -> Path:
return Path(name)
@dosisod working on that. User can return an instance of file like you show.
@dosisod added support for serve filesin latest version. Check the README file. Give it a try and provide feedback please.
Will do! I'll take a look at it in the next couple of days
@dosisod sure
.
Sorry for the delay on this! A couple notes:
- Files passed to
open()should be checked to ensure that they are from inside the directory Lumi is being ran in. If this isn't checked, somebody could steal files from anywhere on the file system:
from lumi import Lumi
def index(file: str):
return open(file)
$ curl -X POST localhost:8080/index -d '{"file":"/home/user/.ssh/id_rsa"}' -H "Content-Type: application/json"
<RSA KEY>
You can check this with the following:
from pathlib import Path
if Path("some/file/name").is_relative_to(Path.cwd()):
# handle file
else:
# return 403 or 404 error
- In the README you use the
rbmode to open the file. Is there any difference betweenr(the default) andrb? I didn't see a difference in my testing.
Thanks!