Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
5955 Переглядів

Iam doing this: 

I recieved the attachment I got from the website


Python Controller:

@ http.route ( '/ topup' , type = 'http' , auth = "public" , website = True ) 
def create_topup ( self , ** kw):

file = kw.get ( 'reciept' , False )
attachment = file.read ()

request.env [ 'model.request' ] .create ( dict ( file = attachment) )


XML File:



<form
id = "topup-form" action = "/ topup" method = "post" enctype = "multipart / form-data" role = "form" style = "display: none;" >

<input
type = "file" multiple = "true" class = "form-control or_website_form_input" name = "reciept" />

</form>



Python Model:

file = fields.Binary ( 'File' , help = "File to check and / or import" )

But the model form view whenever i try to download the file I get the error : 

The server encountered an internal error and it was unable to complete your request. Either the server is overloaded or there is an error in the application.



Аватар
Відмінити
Найкраща відповідь
Heres some part of my controller syntax that already implemented,,

https://pastebin.com/7XgwMzbU

# @author La Jayuhni Yarsyah
@http.route('/upload-image', type="http", auth="user")
def student_admission_upload_image(self, **kw):
    if kw.get('field'):
        data_model = request.env['model.model'].search([('id','=',100)])
        FileStorage = kw.get('image')
        FileExtension = FileStorage.filename.split('.')[-1].lower()
        ALLOWED_IMAGE_EXTENSIONS = ['jpg','png','gif']
        if FileExtension not in ALLOWED_IMAGE_EXTENSIONS:
            return json.dumps({'status':400, 'message':_("Only allowed image file with extension: %s" % (",".join(ALLOWED_IMAGE_EXTENSIONS)))})

        import base64
        FileData = FileStorage.read()
        file_base64 = base64.encodestring(FileData)
        normalized_data = {'field_binnary_name': file_base64}
        data_model.write(normalized_data)
        return json.dumps({'status':200, 'message':_("Success")})

    # if not posted
    raise UserError("Error")
Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
3
жовт. 23
8971
1
вер. 23
3404
1
трав. 23
2362
2
квіт. 23
2915
1
бер. 23
2304