Please let me know how to do this
SERVER_ONE: this is the application server
SERVER_TWO: this is the file storage server
The objective is to
>>> have the user select a file via a form (this is via a Web2py app
running on SERVER_ONE)
>>> when user clicks the submit button, the file is posted to an API
endpoint on SEVER_TWO
>>> the web2py app on SERVER_TWO then saves the file to disk
Here is my code for SERVER_ONE:
def file_upload():
form = FORM(
DIV(
INPUT(
_type = "file",
_name = "file",
requires = IS_LENGTH(MAX_IMAGE_UPLOAD_SIZE, MIN_IMAGE_UPLOAD_SIZE),
)
),
DIV(
INPUT(
_type = "submit",
_value = "UPLOAD IMAGE"
)
),
_method = "post",
_enctype="multipart/form-data",
)
if (form.process().accepted):
r = requests.post(
SERVER_TWO_APP_BASE_URL + "/default/get_file",
files={'file': form.vars.file.file.read()}
)
return dict(
form = form,
)
Here is my code for in default.py controller of SERVER_TWO:
import requests
def get_file():
try:
file = request.files['file']
file.save('', file.filename)
except Exception as e:
with open("_probe_20191013_001", "w") as f:
f.write(str(e))
with open("_probe_20191013_002", "w") as f:
f.write("\n\nthis is a test\n\n")
f.write(str(request))
return dict()
==============================================================
The file is not getting saved on SERVER_TWO
does anyone have any advice on how to accomplish that?
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/76ed4bb0-be9c-4d7a-b60e-d627d9e8a8ef%40googlegroups.com.