Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
3054 Widoki

Hi forum!

I want to upload image from qweb into database and need to display in sales module. I don't know how to encode image before storing in database. Here is my code:-

<!-- Image Upload form -->
<form id="file_upload_form" t-attf-action="/website/form/" method="post" enctype="multipart/form-data" class="form-horizontal mt32">
<div class="row">
<div class="col-md-6">
<div>
<strong>Payment Screenshot</strong>
<input type="file" id="photo" name="photo" class="file" multiple="true" data-show-upload="true" data-show-caption="true" lass="file" data-show-preview="true" />
<button type="submit" name="screenshot" class="btn btn-primary">Upload</button>
</div>
</div>
</div>
</form>

<!-- Image Upload form -->

Here is my Api code which is placed in controller(main.py):-

# Check and insert values from the form on the model <model>
@http.route(['/website_form/'], method='POST', csrf=False, type='http', auth="public", website=True)
def upload_files(self, **post):
values = {}
for field_name, field_value in post.items():
values[field_name] = field_value

http.request.env['button.demo'].sudo().create({
'image': values['photo'],
})

In database, Image is stored like this:- <FileStorage: 'temp.png' ('image/png')>

When I see that field in Sales module, it shows me 257 bytes and then I open this particular image it automatically remove from database

Awatar
Odrzuć
Najlepsza odpowiedź

Hello,

The logic you used seems correct.

but missing is before uploading directly the contents you need to convert to base64 and pass it to create method it should work


Thanks

Awatar
Odrzuć
Autor

How can I convert image into base64?

Powiązane posty Odpowiedzi Widoki Czynność
1
cze 23
4704
3
sie 25
1592
1
lut 23
4453
3
lis 22
4134
2
sie 20
4206