Last active
August 26, 2020 09:11
-
-
Save kooba/49d173e2aeaf93b262d254fb64e157aa to your computer and use it in GitHub Desktop.
Nameko HTTP file upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WEB_SERVER_ADDRESS: 0.0.0.0:8001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WEB_SERVER_ADDRESS: 0.0.0.0:8002 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install: | |
pip install -r requirements.txt | |
run_client: | |
nameko run services:ClientService --config config_client.yaml | |
run_server: | |
nameko run services:ServerService --config config_server.yaml | |
run: | |
$(MAKE) -j2 run_client run_server | |
test: | |
curl localhost:8001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nameko==2.11.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
from nameko.web.handlers import http | |
class ClientService: | |
name = "client" | |
server_url = "http://localhost:8002" | |
@http("GET", "/") | |
def upload_file(self, request): | |
files = {"my_file": open("hello.txt", "rb")} | |
response = requests.post(self.server_url, files=files) | |
return response.text | |
class ServerService: | |
name = "server" | |
@http("POST", "/") | |
def save_file(self, request): | |
for file in request.files.items(): | |
_, file_storage = file | |
file_storage.save(f"saved_{file_storage.filename}") | |
return json.dumps({"ok": True}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have meet some error when do the save_file
the Exception is:
'ImmutableMultiDict' object is not callable
I use vue as my web client.