'Upload file using flask rest api python
I have been using the following script to upload file. This script upload the excel file and will save it in the local folder.
from flask import Flask
import werkzeug
werkzeug.cached_property = werkzeug.utils.cached_property
from werkzeug.utils import secure_filename
from flask_restplus import reqparse
from flask_restplus import Api, Resource
import os
from indivumed_data import *
import pandas as pd
import time
file_upload = reqparse.RequestParser()
file_upload.add_argument('input_file',
type=werkzeug.datastructures.FileStorage,
location='files',
required=True,
help='Input file (xls) containing the clinical data')
file_upload.add_argument('dictionary_file',
type=werkzeug.datastructures.FileStorage,
location='files',
required=True,
help='dictionary file (csv) containing the column values')
app = Flask(__name__)
api = Api(app = app)
app.config['Upload_folder'] = './input/'
@api.route('/upload/')
class my_file_upload(Resource):
@api.expect(file_upload)
def post(self):
if not os.path.exists('./input/'):
os.makedirs('./input/')
args = file_upload.parse_args()
args['input_file'].save(os.path.join(app.config['Upload_folder'],secure_filename(args['input_file'].filename)))
args['dictionary_file'].save(os.path.join(app.config['Upload_folder'],secure_filename(args['dictionary_file'].filename)))
a = [args['input_file'],args['dictionary_file']]
time.sleep(5)
print(type(a))
# input file
reader = pd.ExcelFile(r"./input/Clinical_data.xls")
# dict file
d = pd.read_csv(r"./input/dict_data.csv")
db_rows = d.Provider.unique()
op=final_data(reader, d, db_rows)
return op
if __name__ == '__main__':
app.run(debug=True)
This script runs perfectly if I run it locally. I was trying to run it in GitLab, when I opened the link http://127.0.0.1:5000/ I get This site has been reached error. How do I run this page without an error?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
