示例#1
0
def images(filename):
    """ Route for serving uploaded images """
    if is_allowed_file(filename):
        return send_file(os.path.join(app.config['UPLOAD_FOLDER'], filename))
    else:
        flash("File extension not allowed.")
        return redirect(url_for('home'))
示例#2
0
 def _check_inputs(self):
     if self.file is None:
         print parser.print_help()
         sys.exit()
     if not is_allowed_file(self.file):
         print "Unzipped fastq or fasta files with ext fa,fq,fasta,fastq"
         sys.exit()
示例#3
0
def home():
    if request.method == 'GET':
        # show the upload form
        return render_template('home.html')

    if request.method == 'POST':
        # check if a file was passed into the POST request
        if 'image' not in request.files:
            flash('No file was uploaded.')
            return redirect(request.url)

        image_file = request.files['image']

        # if filename is empty, then assume no upload
        if image_file.filename == '':
            flash('No file was uploaded.')
            return redirect(request.url)

        # check if the file is "legit"
        if image_file and is_allowed_file(image_file.filename):
            filename = secure_filename(generate_random_name(image_file.filename))
            filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
            image_file.save(filepath)
            passed = make_thumbnail(filepath)
            if passed:
                return redirect(url_for('predict', filename=filename))
            else:
                return redirect(request.url)
示例#4
0
def upload_file():
    if request.method == 'POST':
        # check if the post request has the file part
        if 'image' not in request.files:
            return jsonify({"success": False})

        file = request.files['image']
        # if user does not select file, browser also
        # submit an empty part without filename
        if file.filename == '':
            return jsonify({"success": False})
        if file and is_allowed_file(file.filename):
            filename = secure_filename(file.filename)
            uuid_val = uuid.uuid1()
            filename = "{}#{}".format(uuid_val, filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            # now insert into cassandra
            # filename
            session.execute(
                """
                INSERT INTO images (id, path, uploaded)
                VALUES (%s, %s, %s)
                """, (uuid_val, filename, datetime.datetime.now()))

            return jsonify({"success": True, "id": uuid_val})

    return '''
示例#5
0
文件: server.py 项目: Jyo172/Flask
def images(filename):
    """ Route for serving uploaded images """
    if is_allowed_file(filename):
        return send_file(os.path.join('Uploads/', filename))
    else:
        flash("File extension not allowed.")
        return redirect(url_for('home'))
示例#6
0
def index():
    images = utils.get_images(app.config['INPUT_FOLDER'])
    images.sort(key=lambda x: int(x[1]), reverse=True)
    if request.method == 'POST':
        new_file = request.files.get('file', None)
        if new_file is not None and utils.is_allowed_file(new_file.filename):
            filename = str(len(images) + 1) + '.' + new_file.filename.rsplit('.', 1)[1].lower()
            new_file.save(join(app.config['INPUT_FOLDER'], filename))
            return redirect(url_for('processing', image=filename.split('.')[0]))
    return render_template('index.html', images=images)
示例#7
0
def upload():
    images = utils.get_images(app.config['INPUT_FOLDER'])
    images.sort(key=lambda x: int(x[1]), reverse=True)
    new_file = request.files.get('img', None)
    if new_file is not None and utils.is_allowed_file(new_file.filename):
        filename = str(len(images) + 1) + '.' + new_file.filename.rsplit(
            '.', 1)[1].lower()
        new_file.save(join(app.config['INPUT_FOLDER'], filename))
        response = jsonify({'success': True, 'id': filename.split('.')[0]})
        response.status_code = 200
        return response
    response = jsonify({'success': False, 'message': 'Invalid image file'})
    response.status_code = 400
    return response
示例#8
0
def upload():
    results = []

    files = []
    for file in request.files.getlist(config['upload_field']):
        if file and file.filename and is_allowed_file(
                file.filename, config['allowed_extensions']):
            # filename = secure_filename(file.filename)
            basename, ext = os.path.splitext(file.filename)
            filename = get_unique_filename(ext)
            filename = os.path.join(config['upload_folder'], filename)
            file.save(filename)
            files.append((basename, filename))

    for basename, path in files:
        result = check(basename, path, config['epubcheck_path'],
                       stdout_encoding)
        results.append(result)

    session['results'] = json.dumps(results, ensure_ascii=False)
    # return redirect(url_for('validate', results=results))
    return redirect(url_for('validate'))