http://flask-docs-kr.readthedocs.io/ko/latest/patterns/fileuploads.html
I coded the contents on this page, but I don't know which address the picture is sent to.
The programming I'm trying to do is to take pictures with Raspberry Pi and send them to the site (App Inventor). I'd appreciate your help.
Raspberry Pi is using 3B+ and programming is using Python. I've been struggling for weeks because I can't upload the photos even though I'm working on the program. I ask for your help me. Just in case, I'm uploading the entire code.
//import time
import picamera
import datetime
import requests
import os
from flask import Flask, redirect, url_for
from werkzeug import secure_filename
import serial
port = "/dev/ttyACM0"
serialFromArduino = serial.Serial(port, 9600)
serialFromArduino.flushInput()
while True:
if(serialFromArduino.inWaiting() > 0):
input = serialFromArduino.read(1)
# # print(input)
if input=='a':
continun = 1
while continun == 1 :
with picamera.PiCamera() as camera:
now = datetime.datetime.now()
filename = now.strftime('%Y-%m-%d %H:%M ')
camera.brightness = 60
camera.start_preview(fullscreen=False, window=(100,20,1024,768))
time.sleep(5)
s = datetime.datetime.now()
camera.capture(filename + '.jpg')
camera.stop_preview()
continun = 0
UPLOAD_FOLDER = '/path/to/the/uploads'
ALLOWED_EXTENSIONS = set(['txt','pdf','png','jpg','jpeg','gif'])
app=Flask(__name__)
app.config['UPLOAD_FOLDER']=UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and \
filename.raplit('.',1)[1] in ALLOWED_EXTENSIONS
@app.route('/',methods=['GET','POST'])
def upload_file():
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))
return redirect(url_for('uploaded_file',
filename=filename))
return '''
<!doctype html>
<html> "http://192.168.0.84"
<title>Upload new File</title>
<h1>Hello DDL!</h1>
<h1>Upload new File</h1>
<form action="" method=post enctype=multipart/from-data>
<p><input type=file name=file>
<input type=submit value=Upload>
</form>
'''
© 2024 OneMinuteCode. All rights reserved.