I need to send a wave file from client to server ,
receive the file at the server side to do some some processing and convert it to text file ,
then send the text file back to the server .
I shouldn't use socket .
I am new to python and I have very little knowledge on how to do the task .
I used this code at the client side :
# We'll render HTML templates and access data sent by POST
# using the request object from flask. Redirect and url_for
# will be used to redirect the user once the upload is done
# and send_from_directory will help us to send/show on the
# browser the file that the user just uploaded
from flask import Flask, render_template, request, redirect, url_for, send_from_directory
from werkzeug import secure_filename
# Initialize the Flask application
app = Flask(__name__)
# This is the path to the upload directory
app.config['UPLOAD_FOLDER'] = 'uploads/'
# These are the extension that we are accepting to be uploaded
app.config['ALLOWED_EXTENSIONS'] = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'wav'])
# For a given file, return whether it's an allowed type or not
return '.' in filename and \
filename.rsplit('.', 1) in app.config['ALLOWED_EXTENSIONS']
# This route will show a form to perform an AJAX request
# jQuery is loaded to execute the request and update the
# value of the operation
# Route that will process the file upload
# Get the name of the uploaded file
file = request.files['file']
# Check if the file is one of the allowed types/extensions
if file and allowed_file(file.filename):
# Make the filename safe, remove unsupported chars
filename = secure_filename(file.filename)
# Move the file form the temporal folder to
# the upload folder we setup
# Redirect the user to the uploaded_file route, which
# will basicaly show on the browser the uploaded file
# This route is expecting a parameter containing the name
# of a file. Then it will locate that file on the upload
# directory and show it on the browser, so if the user uploads
# an image, that image is going to be show after the upload
if __name__ == '__main__':
I am not sure if I shall change the host from " 0.0.0.0 " to the Ip address of the server ?
Is this code enough to send a wave file from the client ?
How can I receive the file at the server side ?
Can any body help ?
At serverside you can receive the file by using the associative array
$_FILES. Then you must move the uploaded file and then you can process it to a textfile.
I need to send a wave file from client to server , receive the file at the server side to do some some processing and convert it to text file , then send the text file back to the server .
I think you meant
[...] then send the text file back to the client
To do that, you just open the url in Python as header you send the file, it will be processed to text and then you print the text on the webpage. With Python you can read the whole page into a string and finish.
wav_to_text = openurl("http://www.example.com/wav_to_text.php", file="files/example.wav") text = wav_to_text.readpage() print(text) # ... Do what you want with the text