Skip to content

Instantly share code, notes, and snippets.

@kooba
Last active August 26, 2020 09:11
Show Gist options
  • Save kooba/49d173e2aeaf93b262d254fb64e157aa to your computer and use it in GitHub Desktop.
Save kooba/49d173e2aeaf93b262d254fb64e157aa to your computer and use it in GitHub Desktop.
Nameko HTTP file upload
WEB_SERVER_ADDRESS: 0.0.0.0:8001
WEB_SERVER_ADDRESS: 0.0.0.0:8002
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
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})
@iceicedream
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment