Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Support for File #9

Open
1 of 2 tasks
tanmoysrt opened this issue Nov 29, 2022 · 7 comments
Open
1 of 2 tasks

Support for File #9

tanmoysrt opened this issue Nov 29, 2022 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@tanmoysrt
Copy link
Owner

tanmoysrt commented Nov 29, 2022

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 -

  • **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 Add supports for application/x-www-form-urlencoded and multipart/form-data types #8 . After then we can work on this. When the file will receive we will cast it to file and pass it to function
@tanmoysrt tanmoysrt pinned this issue Dec 1, 2022
@tanmoysrt tanmoysrt unpinned this issue Dec 1, 2022
@tanmoysrt tanmoysrt added the enhancement New feature or request label Dec 10, 2022
@dosisod
Copy link

dosisod commented Dec 21, 2022

@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)

@tanmoysrt
Copy link
Owner Author

@dosisod working on that. User can return an instance of file like you show.

@tanmoysrt
Copy link
Owner Author

@dosisod added support for serve filesin latest version. Check the README file. Give it a try and provide feedback please.

@tanmoysrt tanmoysrt self-assigned this Dec 22, 2022
@dosisod
Copy link

dosisod commented Dec 23, 2022

Will do! I'll take a look at it in the next couple of days

@tanmoysrt
Copy link
Owner Author

@dosisod sure

@tanmoysrt
Copy link
Owner Author

.

@dosisod
Copy link

dosisod commented Jan 12, 2023

Sorry for the delay on this! A couple notes:

  1. 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
  1. In the README you use the rb mode to open the file. Is there any difference between r (the default) and rb? I didn't see a difference in my testing.

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants