def file_post():
	#try to access uploaded file from Flask's request.files dictionary
	file = request.files.get("file")
	if not file:
		data = {"message": "Could not find file data"}
		return Response(json.dumps(data), 422, mimetype="application/json")

	#secure_filename() --> function(from Werkzeug) which creates a safe version of the filename supplied by client
	filename = secure_filename(file.filename)
	#use the secure filename to create a File object and add it to the database and commit
	db_file = models.File(filename=filename)
	session.add(db_file)
	session.commit()
	#save file to an upload folder using our upload_path() function
	file.save(upload_path(filename))

	#return file information
	data = db_file.as_dictionary()

	"""View how data above looks
	print ("file data from file_post() is {}".format(data))
	print ("")
	print("Response data is {}".format(json.dumps(data)))
	"""
	return Response(json.dumps(data), 201, mimetype="application/json")
Exemplo n.º 2
0
def file_post():
    file = request.files.get("file")
    if not file:
        data = {"message": "Could not find file data"}
        return Response(json.dumps(data), 422, mimetype="application/json")

    filename = secure_filename(file.filename)
    print "printing upload path:"
    print upload_path(filename)
    db_file = File(name=filename)
    session.add(db_file)
    session.commit()
    file.save(upload_path(filename))                                                                          
    data = db_file.as_dictionary()
    print data
    return Response(json.dumps(data), 201, mimetype="application/json")
Exemplo n.º 3
0
def analyze_song(id):
    song = session.query(models.Song).get(id)
    if not song:
        data = {"message": "Could not find song with id {}".format(id)}
        return Response(json.dumps(data), 422, mimetype="application/json")
    filename = song.file.filename
    data = json.dumps(analysis.analyse(upload_path(filename)))
    return Response(data, 200, mimetype="application/json")
Exemplo n.º 4
0
def analyze_song(id):
    song = session.query(models.Song).get(id)
    if not song:
        data = {"message": "Could not find song with id {}".format(id)}
        return Response(json.dumps(data), 422, mimetype="application/json")
    filename = song.file.filename
    data = json.dumps(analysis.analyse(upload_path(filename)))
    return Response(data, 200, mimetype="application/json")
Exemplo n.º 5
0
def song_analysis(id):
    song = session.query(models.Song).get(id)
    if not song:
        data = {"message": "Could not find song with id {}".format(id)}
        return Response(json.dumps(data), 404, mimetype="application/json")

    path = upload_path(song.file.filename)
    data = analysis.analyse(path)
    return Response(json.dumps(data), 200, mimetype="application/json")
Exemplo n.º 6
0
def file_post(post):
    file = request.files["file"]
    if not file:
        data = {"message": "Could not find file data or filetype not permitted"}
        return Response(json.dumps(data), 422, mimetype="application/json")

    #filename = secure_filename(file.filename)
    
    file.save(upload_path(post.main_image()))
    #gen_thumbnail(filename)
    #thumbnail = thumbnails.get_thumbnail(upload_path(filename), '50x50', crop='center')
    #thumbnail.save(upload_path('thumb_'+filename))
    #return send_from_directory(upload_path(), filename)
Exemplo n.º 7
0
def file_post():
    file = request.files.get("file")
    if not file:
        data = {"message": "Could not find file data"}
        return Response(json.dumps(data), 422, mimetype="application/json")

    filename = secure_filename(file.filename)
    db_file = models.File(filename=filename)
    session.add(db_file)
    session.commit()
    file.save(upload_path(filename))

    data = db_file.as_dictionary()
    return Response(json.dumps(data), 201, mimetype="application/json")
Exemplo n.º 8
0
def analyse_song():
    file = request.files.get("file")
    if file.id == "<id>":
        pass
    if file.id != "<id>":
        data = {"message": "Wrong file id"}
        return Response(json.dumps(data), 422, mimetype="application/json")
    filename = secure_filename(file.filename)
    db_file = models.File(filename=filename)


# pass in the path of the uploaded file
    analyse(upload_path(filename))
    return Response(json.dumps(data), 201, mimetype="application/json")
def song_analyze(id):
	#check wether a song with the correct ID exists
	song = session.query(models.Song).get(id)
	if not song:
		message = "Could not find song with id {}".format(id)
		data = json.dumps({"message": message})
		return Response(data, 404, mimetype="application/json")
	#get the filename of the song from the database
	song_file = session.query(models.File).filter_by(id=song.file_id).first()
	#save file to an upload folder using upload_path() function
	song_file_path = upload_path(song_file.filename)
	#call analyse function, passing in path of the uploaded file
	file_analysis = analysis.analyse(song_file_path)
	data = json.dumps(file_analysis)
	#return results of analysis function as a JSON object
	return Response(data, 201, mimetype="application/json")
def song_analyze(id):
    #check wether a song with the correct ID exists
    song = session.query(models.Song).get(id)
    if not song:
        message = "Could not find song with id {}".format(id)
        data = json.dumps({"message": message})
        return Response(data, 404, mimetype="application/json")
    #get the filename of the song from the database
    song_file = session.query(models.File).filter_by(id=song.file_id).first()
    #save file to an upload folder using upload_path() function
    song_file_path = upload_path(song_file.filename)
    #call analyse function, passing in path of the uploaded file
    file_analysis = analysis.analyse(song_file_path)
    data = json.dumps(file_analysis)
    #return results of analysis function as a JSON object
    return Response(data, 201, mimetype="application/json")
def song_delete(id):
	song = session.query(models.Song).get(id)

	if not song:
		message = "Could not find song with id {}".format(id)
		data = json.dumps({"message":message})
		return Response(data, 404, mimetype="application/json")

	song_file = session.query(models.File).filter_by(id=song.file_id).first()
	print song_file.filename
	os.remove(upload_path(song_file.filename))
	session.delete(song_file)
	session.commit()

	message = "Song with id {} has been deleted".format(id)
	data = json.dumps({"message":message})
	return Response(data, 201, mimetype="application/json")
def song_delete(id):
    song = session.query(models.Song).get(id)

    if not song:
        message = "Could not find song with id {}".format(id)
        data = json.dumps({"message": message})
        return Response(data, 404, mimetype="application/json")

    song_file = session.query(models.File).filter_by(id=song.file_id).first()
    print song_file.filename
    os.remove(upload_path(song_file.filename))
    session.delete(song_file)
    session.commit()

    message = "Song with id {} has been deleted".format(id)
    data = json.dumps({"message": message})
    return Response(data, 201, mimetype="application/json")
Exemplo n.º 13
0
def file_post():
    """ Handling the uploads """
    # Try to access the uploaded file
    file = request.files.get("file")
    if not file:
        # Return error if file not found
        data = {"message": "Could not find file data"}
        return Response(json.dumps(data), 422, mimetype="application/json")
    
    # Use the Werkzeug function to create a safe version of the filename
    filename = secure_filename(file.filename)
    db_file = models.File(filename=filename)
    session.add(db_file)
    session.commit()
    file.save(upload_path(filename))
    
    # Return the file information
    data = db_file.asDictionary()
    return Response(json.dumps(data), 201, mimetype="application/json")
Exemplo n.º 14
0
def file_post():
    # Attempt to obtain the file uploaded file from Flask's request.files dict
    file = request.files.get("file")
    # If the file is not found, return an error
    if not file:
        data = {"message": "Could not find file data"}
        return Response(json.dumps(data), 422, mimetype="application/json")
    # Werkzeug secure_filename function provides safe version of file name
    # For instance ../../../etc/passwd is replaced by etc_passwd
    filename = secure_filename(file.filename)
    # Create file object with safe filename
    db_file = models.File(name=filename)
    # Add the file object to the session and commit
    session.add(db_file)
    session.commit()
    # Save the file to the upload path using the safe file name
    file.save(upload_path(filename))

    # Create a dict object of file
    data = db_file.as_dictionary()
    # Return a response with 201 CREATED
    return Response(json.dumps(data), 201, mimetype="application/json")
Exemplo n.º 15
0
def file_post():
    # Attempt to obtain the file uploaded file from Flask's request.files dict
    file = request.files.get("file")
    # If the file is not found, return an error
    if not file:
        data = {"message": "Could not find file data"}
        return Response(json.dumps(data), 422, mimetype="application/json")
    # Werkzeug secure_filename function provides safe version of file name
    # For instance ../../../etc/passwd is replaced by etc_passwd
    filename = secure_filename(file.filename)
    # Create file object with safe filename
    db_file = models.File(name=filename)
    # Add the file object to the session and commit
    session.add(db_file)
    session.commit()
    # Save the file to the upload path using the safe file name
    file.save(upload_path(filename))

    # Create a dict object of file
    data = db_file.as_dictionary()
    # Return a response with 201 CREATED
    return Response(json.dumps(data), 201, mimetype="application/json")
def file_post():
    #try to access uploaded file from Flask's request.files dictionary
    file = request.files.get("file")
    if not file:
        data = {"message": "Could not find file data"}
        return Response(json.dumps(data), 422, mimetype="application/json")

    #secure_filename() --> function(from Werkzeug) which creates a safe version of the filename supplied by client
    filename = secure_filename(file.filename)
    #use the secure filename to create a File object and add it to the database and commit
    db_file = models.File(filename=filename)
    session.add(db_file)
    session.commit()
    #save file to an upload folder using our upload_path() function
    file.save(upload_path(filename))

    #return file information
    data = db_file.as_dictionary()
    """View how data above looks
	print ("file data from file_post() is {}".format(data))
	print ("")
	print("Response data is {}".format(json.dumps(data)))
	"""
    return Response(json.dumps(data), 201, mimetype="application/json")
Exemplo n.º 17
0
def uploaded_file(filename):
    return send_from_directory(upload_path(), filename)
def uploaded_file(filename):
    """
	end_from_directory function -> send a file from the given directory using send_file()
	where send_file()-> send contents of a file to a client, using the most efficient way possible
	"""
    return send_from_directory(upload_path(), filename)
def uploaded_file(filename):
	"""
	end_from_directory function -> send a file from the given directory using send_file()
	where send_file()-> send contents of a file to a client, using the most efficient way possible
	"""
	return send_from_directory(upload_path(), filename)
Exemplo n.º 20
0
def gen_thumbnail(filename):
	  height = width = 50
	  original = Image.open(upload_path(filename))
	  thumbnail = original.resize((width, height))
	  thumbnail.save(upload_path('thumb_'+filename))
Exemplo n.º 21
0
def uploaded_file(filename):
    """ Serve the file from the upload path """
    return send_from_directory(upload_path(), filename)
Exemplo n.º 22
0
def uploaded_file(filename):
    return send_from_directory(upload_path(), filename)