jane1912
jane1912

Reputation: 85

IOError: [Errno2] No such file or directory: for input files to flask

This is a client file with flask framework running inside my docker container . I would like to upload files from my local folder C:/Users/RB287JD/Desktop/upload/file.txt

Unfortunately the flask application is unable to find it. If I run this,

APP_ROOT = os.path.abspath(os.path.dirname(__file__))
UPLOAD_FOLD = '/c/Users/RB287JD/Desktop/upload/'
UPLOAD_FOLDER = os.path.join(APP_ROOT, UPLOAD_FOLD)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

class mainSessRunning():

    def __init__(self):
        host, port = FLAGS.server.split(':')
        channel = implementations.insecure_channel(host, int(port))
        self.stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)

        self.request = predict_pb2.PredictRequest()
        self.request.model_spec.name = 'modelX'
        self.request.model_spec.signature_name = 'prediction'

    def inference(self, val_x):
        data = val_x
        self.request.inputs['input'].CopyFrom(tf.contrib.util.make_tensor_proto(data))
        result = self.stub.Predict(self.request, 5.0)
        return result

run = mainSessRunning()


# Define a route for the default URL, which loads the form
@app.route('/pred', methods=['POST'])
def pred():
    f = request.files['file']
    f.save(os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(f.filename)))
    result = run.inference(f)
    rs = json_format.MessageToJson(result)
    return jsonify({'result':rs})

It throws error,

File "/usr/local/lib/python2.7/dist-packages/werkzeug/datastructures.py", line 2725, in save dst = open(dst,'wb') IOError: [Errno2] No such file or directory:'/c/Users/RB287JD/Desktop/upload/File.txt'

But this is where (C:\Users\RB287JD\Desktop\upload\File.txt) my file exists.

Upvotes: 0

Views: 546

Answers (1)

Veikko
Veikko

Reputation: 3620

I assume your Python program does not see your host machine local directory from the container.

You did not provide your dockerfile or docker command you used for running the container. You need to declare a volume in your dockerfile and bind a local directory from your computer to the container volume.

You can find more information about declaring a volume and mounting it here:

Hope this helps.

Br,

Veikko

Upvotes: 1

Related Questions