blob: 2c9c4b94f80d0a7315bd1e8143afd27aa1b34bf4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import os
import subprocess
import shlex
from flask import Flask, flash, request, redirect, make_response, url_for
from werkzeug.utils import secure_filename
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
if 'data' not in request.form:
flash("No string input")
file = request.files['file']
if file:
if file.filename == '':
flash('No selected file')
return redirect(request.url)
try:
binary = subprocess.check_output(
"./bmpencode /dev/stdin /dev/stdout {}".format(shlex.quote(request.form['data'])),
stdin=file.stream,
stderr=subprocess.PIPE,
shell=True
)
response = make_response(binary)
response.headers.set('Content-Type', 'image/bmp')
response.headers.set('Content-Disposition', 'attachment', filename='encoded.bmp')
return response
except subprocess.CalledProcessError as e:
return e.stderr
return '''
<!doctype html>
<title>Hide Text in a BMP</title>
<h1>Upload new File</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=text name=data>
<input type=submit value=Upload>
</form>
'''
|