안녕 모두는 파이썬에 약간의 새로운 메신저. 그래서 나에게는 혼란스러운 문제가있다. 데이터베이스에 이미지를 저장해야하고 그 후에는 클라이언트 측에서 각 이미지를 표시해야합니다. Im은 (는) 휴식 요청을 위해 Flask를 사용합니다.캔트 디스플레이 이미지, PyMongo
그래서 여기 난 내 요청을 얻을 내 DB에 저장 여기 submitind에 대한
<form action="/upload" method="post" enctype="multipart/form-data">
<label for="image">Select image</label>
<input type="file" name='img' id='image'>
<input type="submit" id='upload_img'>
</form>
을 내 간결체 한자 marckup을 가지고
@app.route("/upload", methods=["POST"])
def upload_image():
# get current image file
img_file = request.files['img']
# get Content Type and File Name of current image
content_type = img_file.content_type
filename = img_file.filename
# save to GridFS my image
# fields <-- recive the id of just saved image
fields = db.FS.put(img_file, content_type=content_type, filename=filename)
# store the filename and _id to another database
# so here we can much morea easaly get image from our GridFS
db.Mongo['images'].insert({"filename": filename, "fields": fields})
return index(images=[])
내 간단한 데이터베이스 모델
class db(object):
URI = "mongodb://localhost:27017"
Mongo = None
FS = None
@staticmethod
def initialize():
client = pymongo.MongoClient(db.URI)
db.Mongo= client['gallery']
db.FS = GridFS(Database.DATABASE)
그리고 모든 저장이 성공적입니다.
는 DB에서 내 이미지를을 취득합니다 및 디스플레이 이미지에 대한 마크 업이 응답에서
<div>
<img src="data:image/png;base64,{{images}}" alt="">
<div>{{images}}</div>
</div>
입니다 clietn 여기
@app.route('/get_all_images')
def get_image():
images = db.Mongo['gallery'].find({})
# try to get just a first image _id and fing it at GridFS files
image = db.FS.get(images[0]["fields"])
#send to the client
return index(images=image.read())
에 보내려고하고 finnaly 나는 이런 식으로 뭔가를 얻을 enter image description here
응답은 다음과 같이이다 : B '\ x89PNG 연구 \ n 개의 \ X1A \ 없음 \ \ x00에서 \ x00에서 \ x00에서 \ rIHDR \ x00에서 \ x00에서 \ x00w \ x00에서 \ x00에서 \ x00에서 \ x7f \ X08 \ X06 \ x00에서 \ x00에서 \ x00에서 \ xd5j] \ xe7 \ x00에서 \ x00에서 \ x00부터 \ x19tEXtSoftware \ x00Adobe ImageReadyq \ xc9e < \ x00에서 \ x00부터 \ X03 "iTXtXML : com.adobe.xmp \ x00에서 \ x00에서 \ x00에서 \ x00에서 \ x00부터
problam은입니다 I 이 바이트 형식을 실제 이미지로 변환하고 데이터베이스에서 직접 웹 페이지에 표시하는 방법을 설명 할 수 없습니다.
나는 내 마음이 타격 그만둬 정말 그것으로 작업하는 방법을 알아 보았 해달라고하는 방법을 몇 가지이 problam..but를 해결하기 위해 여러 변종을 만들려고. 시간에 대한
감사합니다 :)
somebady 내가 클라이언트 측에 데이터베이스에서 이미지를 표시 할 수있는 방법 어떤 idias이나 조언이 있으면 ...
나는이 problam은 매우 일반적이라고 생각하지만 ... 나는이 경우에 처음으로 붙어있다. –