cloudinary.Exceptions.Error: ไฟล์ว่างเปล่าโดยใช้ Flask

ฉันใช้ cloudinary เพื่ออัพโหลดไฟล์จากแอพ flask ของฉัน ฉันติดตามโค้ดตัวอย่างพื้นฐานนี้โดย pycloudinary สำหรับ flask : https://github.com/cloudinary/pycloudinary/tree/master/samples/basic แต่ฉันยังคงได้รับข้อผิดพลาดเดิม

cloudinary.exceptions.Error 
cloudinary.exceptions.Error: Empty file

คำขอโพสต์ไฟล์ของฉันพร้อมรูปภาพหลายส่วนและชื่อคีย์ ก่อนหน้านี้ฉันอัพโหลดไฟล์ไปยังโฟลเดอร์คงที่เรียบร้อยแล้ว

ฉันควรทำอย่างไรดี ?

def upload_files():
    upload_result = None
    file_to_upload = request.files['image']
    if file_to_upload:
        upload_result = upload(file_to_upload)
        return "Success!"
    else:
        return "Failed!"

person monti    schedule 08.10.2020    source แหล่งที่มา


คำตอบ (1)


file_to_upload = request.files['image'] ควรเป็น file_to_upload = request.files['file'] หรือไม่

request.files เป็น ImmutableMultiDict() ที่ file เป็นคีย์ ไม่ใช่ image

ดีที่สุด, โม

person user13764453    schedule 08.10.2020
comment
ขอบคุณที่ตอบคำถามนี้ แต่ฉันลองไปแล้วและผลลัพธ์คือ KeyError - person monti; 09.10.2020