Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

Add Attachement From website.

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
attachmentwebsite
2 Antwoorden
26364 Weergaven
Avatar
samer alsarhan

I am trying to add a file upload in web page 

html

<input type="file" class="form-control" name="doxFile" id="dox_dox"/>
<button class="btn btn-default" onclick="Uptest();">Upload</button>

js

function Uptest()
{
var file = $("#dox_dox")[0].files[0];
var formData = new FormData();
var reader = new FileReader();
reader.onload = function(){
var dataURL = reader.result;
formData.append('doxFile', dataURL);
formData.append('name', file.name);
formData.append('type', file.type);
$.ajax(
{
url : '/savedox/',
type: "POST",
data : formData,
dataType:'json',
cache: false,
processData: false,
contentType: false,

success: function(data, textStatus, jqXHR){
console.log('Saved')
}})
}
reader.readAsDataURL(file);

py

@http.route('/savedox/', csrf=False, auth='public', method=['POST', 'GET'])
def save_dox(self, **kw):
# cgitb.enable()
data = kw.get('doxFile')
file_name = kw.get('name')
file_size = kw.get('size')
file_type = kw.get('type')
local_context = dict(request.env.context, force_company = request.env.user.company_id.id,company_id =request.env.user.company_id.id)

sam = request.env['ir.attachment'].new({'name':file_name,'db_datas':data,'datas_fname':file_name,
'type':'binary','file_size':file_size,'mimetype':file_type
})
samo = sam._convert_to_write({name: sam[name] for name in sam._cache})
new_sam = request.env['ir.attachment'].with_context(local_context).sudo().create(samo)

what happing is it add the file to the ir.attachemt without errors and when I am trying to download the file it work only if the file is 'txt or zip' the other file type like (.jpg,pdf,xls) it downloads but when I open it it's in bad form like if there is encoding problem,


any help,

1
Avatar
Annuleer
samer alsarhan
Auteur

also in the py I tried "datas" instead of "db_datas"

Avatar
Jainesh Shah(Aktiv Software)
Beste antwoord

Hi samer al- sarhan,

You can try using this code:

Xml code :

<template id="detail" name="Project Detail">
       <t t-call="website.layout">
           <div class="col-md-offset-5 col-sm-offset-4 col-sm-8 col-md-7" style="margin-top:30px;">
               <form action="/project/uploaded" method="post" class="s_website_form form-horizontal container-fluid mt32" enctype="multipart/form-data" id="file_upload_form">
                   <div t-attf-class="form-group">
                       <div class="col-md-7 col-sm-8">
                           <input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
                           <input type="hidden" name="project_id" t-att-value="project.id"/>
                           <input type="file" name="attachment" class="file" multiple="true" data-show-upload="true" data-show-caption="true" lass="file" data-show-preview="true" id="project.id"/>
                           <button type="submit" name="Upload" style="margin-top:20px;" class="fa fa-upload">
                               Upload
                           </button>
                       </div>
                   </div>
               </form>
           </div>
       </t>
   </template>

.py code :

@http.route('/project/uploaded', type='http', auth="public", website=True)
   def upload_files(self, **post):
       values = {}
       if post.get('attachment',False):
           Attachments = request.env['ir.attachment']
           name = post.get('attachment').filename      
           file = post.get('attachment')
           project_id = post.get('project_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': attachment.encode('base64'),
           })
           value = {
               'attachment' : attachment_id
           }
            return request.render("modulename.template_to_render", value)

Hope this will help you.

Thanks.

4
Avatar
Annuleer
Gabriel Hernandez

Really good!, but when I use Safari the attachment are not created, I noticed that with safari the type is 'application/octet-stream', but I don't know how to fix this. Do you know something about it? Thanks!

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
How to upload multiple file in website, and add it as an attachment to a new record? Opgelost
attachment controller website
Avatar
Avatar
3
jul. 21
22647
Attachment from website v9c
attachment helpdesk website
Avatar
0
jul. 17
2965
How do I remove the numbers from the slugs in my blog and blogpost? Opgelost
website
Avatar
Avatar
Avatar
Avatar
3
sep. 25
2479
Login Website Opgelost
website
Avatar
3
okt. 25
149265
500 Server Error after upgrading from 18.0 to 18.4 Odoo Online
website
Avatar
Avatar
1
sep. 25
1812
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now