I wrote a python program which takes a file (pdf/docx) in a post request, stores it in the temp folder and then parses it. I deployed it to AWS Lambda using serverless.
When I make a POST call to the API (using Postman), the file gets uploaded in the /tmp, and it prints the size and everything properly. However the main function when reading the file returns blank.
I tried putting a sample file in the project root and reading it, worked perfectly. So just doesn't read from the /tmp folder. It doesn't throw an error either. Just returns null.
The relevant code:
tmp_dir = tempfile.gettempdir()
resumes_dir = os.path.join(tmp_dir, 'resumes')
if not os.path.exists(resumes_dir):
os.mkdir(resumes_dir)
@app.route("/", methods=['GET', 'POST'])
def resume_parser():
if request.method == 'POST':
resume = request.files.get('resume')
file_extension = pathlib.Path(resume.filename).suffix
file_name = generate_file_name(file_extension)
file_path = os.path.join(resumes_dir, secure_filename(file_name))
resume.save(file_path)
parser = ResumeParser(file_path) # /tmp/ file_path doesn't work, but a file path from the root works.
return parser.get_extracted_data()
elif request.method == 'GET':
return 'Welcome!'
The ResumeParser is a function I wrote which analyses the file and returns data extracted. I cannot directly store on root since lambda doesn't allow storing anywhere except /tmp.