My app has a python (bottle.py) backend and an html/jquery frontend.
I am getting a text file using 'input' in a form and uploading it in background, using event handler on a python side. The event handler then parses the file (calling file.readline()
repetitively) and returns some result in json form back.
Everything goes well until I need to parse the file in python.
Here is my javascript:
function UploadFile() {
var file = $('#data')[0].files[0];
var formData = new FormData();
formData.append("file", file);
$.ajax({
url: 'plates',
type: 'POST',
data: formData,
cache: false,
contentType: false,
processData: false,
success: function(data){
...
}
});
}
When I recieve the POST request on the python side, I can read it only with request.body.read().decode()
. If I am trying request.files.data.file.read()
, I am getting the 'broken pipe' error:
socket.error: [Errno 32] Broken pipe
I can just get the text with request.body.read().decode()
, save them to file and then load it and parse. But I would like to avoid creating files that are not necessary to create, and want to do everything in memory.
Why does request.body.read().decode()
work and request.files.data.file.read()
doesn't?
Is there any way to parse the file with my existing function while not writing it to a disk?