I tried to save a large string data into a text file using following code.
@api.route("/upload/{project_name}/files")
async def receive_files(req, resp, *, project_name):
@api.background.task
def save_files(uploaded_data, project_name):
filename = uploaded_data['filename']
filedata = uploaded_data['data']
with open(f"data/{project_name}/{filename}", "w", encoding="utf-8", newline="") as f:
f.write(str(data))
print('successfully saved', filename)
data = await req.media()
save_files(data, project_name)
resp.media = {'success': True}
When I send a large file like 600MB csv file to this function, this process failed due to out of memory. It works with files less than 300MB. Is there any way I can optimize this function?? Thank you in advance.
I am using python-responder and a laptop with 16GB RAM
I forgot to pass the right media format, files for responder-python.
data = await req.media(format='files')
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments