将文件上传到2D阵列Flask / HTML

时间:2020-03-26 08:17:54

标签: javascript python html flask

HTML

<form class="formLogin" action="/addC" method="post">
                            <div class="itemImage">
                                <image id="blah" class="image" src="https://static.thenounproject.com/png/340719-200.png" alt="Uploaded Image">
                                <input name="itemImage" type='file' onchange="readURL(this);" />
                            </div>

                            <div class="addItemName">
                                <h2>Name Of Item</h2>
                                <input type="text" name="itemName" placeholder="Name Of Item" required> 
                            </div>
                            <div class="addItemDescription">
                                <h2>Description Of Item</h2>
                                <textarea style="resize: none;" name="itemDescription" placeholder="Description/Other Infomation about Item" required>
                                </textarea>
                            </div>
                            <h2>Catagory Of Item</h2>
                            <div class="addItemCatagory">
                                <input type="radio" name="Catagory" value="clothes"> Clothes<br>
                                <input type="radio" name="Catagory" value="lunchbox"> Lunchbox<br>
                                <input type="radio" name="Catagory" value="toys"> Toys<br>
                                <input type="radio" name="Catagory" value="other"> Other<br>
                            </div>
                            <br>
                            <input class="" type="submit" value="Add Item" onlick="loginCheck()">
</form>

Python

@app.route("/addC" , methods=["GET", "POST"])
def addPageC():
    url=request.form.get("itemImage")
    if url is None:
        url=""
    name=request.form["itemName"]
    date=datetime.date(datetime.now())
    description=request.form["itemDescription"]
    ID=logins[session["currentUser"]]["studentID"]
    catagory=request.form["Catagory"]
    lostItems.append([url, name, date, description, ID, catagory])
    return redirect("/browse")

JS

function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function(e) {
            $('#blah')
                .attr('src', e.target.result);
        };

        reader.readAsDataURL(input.files[0]);
    }
}

我正在尝试检索一组上传的数据(特别是图片)并将其保存在2D数组中,然后进行处理并显示在html页面的其他位置。而当图片上传后,图片的单桅三角帆船将作为预览

0 个答案:

没有答案