Hi there,
Has anybody tried to upload multiple file from the Odoo website, and then call a controller with method post to create a record and save the attachment?
The input type file in my template view
<div class="form-group row form-field o_website_form_required_custom">
<div class="col-md-4 col-sm-3 text-right">
<label class="control-label" for="project_managment"></label>
</div>
<div class="col-md-6 col-sm-7">
<input type="file" name="attachment" class="file" multiple="true" data-show-upload="true" data-show-caption="true" lass="file" data-show-preview="true"/>
</div>
</div>
in my controller
@http.route(['/upload/file/<model("model.custom"):object>/<model("model.custom2"):object2>/confirm'],type='http',auth='user',website=True)
def convocatoria_proyecto_info(self, convocatoria, proyecto, **kwargs):
values = {}
if kwargs.get('attachment',False):
Attachments = request.env['ir.attachment']
name = kwargs.get('attachment',False).filename
file = kwargs.get('attachment',False)
project_id = proyecto.id
attachment = file.read()
attachment_id = Attachments.sudo().create({
'name':name,
'datas_fname': name,
'res_name': name,
'type': 'binary',
'res_model': 'model.model',
'res_id': project_id,
'datas': base64.b64encode(attachment),
})
values = {'attachment' : attachment_id}
return request.render("modulename.template_to_render", value)
Could anybody tell me in which format I should pass the multiple value, how to get & pass attach it as an attachment on the just create record?
Regards
Try this one: http://learnopenerp.blogspot.com/2019/01/add-attachement-file-from-odoo-website.html
@Sehrish at least read the title! It says MULTIPLE files!!!
I'm having the same problem with multiple files. The problem is that you have only one file in your post variable. If you could get the files in a list you just call the create method in "for attachment in post.get(attachment)"