Skip to content

Instantly share code, notes, and snippets.

@kooba

kooba/Makefile

Last active Aug 26, 2020
Embed
What would you like to do?
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
nameko==2.11.0
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

This comment has been minimized.

Copy link

@iceicedream iceicedream commented Aug 26, 2020

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
You can’t perform that action at this time.