Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

Upload a file by code thanks to ir.attachment

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
filestorecreateir_attachment
6 Replies
31963 Tampilan
Avatar
Fabien REMY

Hi all,

I try to upload a file generated on the server by an OpenERP (v 7.0) cron task via the ir.attachment object.

 When I set the parameters passed to the ir.attachment create method, I don't know what kind of object I need for the datas parameter ?

Do I need an absolute path to my file ? An instance of my opened file ? something else ?

The error I have is : "Cannot determine mime type... I guess I don't give the right type of object.


Example :


document_vals = {'name': name_file_export_final,                        -> filename.csv

                             'datas': fname,                                                  -> path to my file (under Windows)

                             'datas_fname': name_file_export_final,            -> filename.csv

                             'res_model': self._name,                                   -> My object_model

                             'res_id': gm_record_id,                                     -> the id linked to the attachment.

                             'type': 'binary' }

ir_id = ir_attachement_obj.create(cr, uid, document_vals, context)


The record is created within the table ir_attachment, I can see the attached file on my object on the web application, but when I download the file it is stangely encoded.

My developments are done under windows, but the server is under Unix (if it could be usefull for my problem)

Thank you for your answers.

Fabien.

2
Avatar
Buang
Temur

You mean file names are encoded, like 68bb912c1711dade5df906449f0d5dd3 ?

Temur

that's filename as it stored in the odoo filestore. it avoids duplicated files in filestore. the real filenames are stored in the database, for download these files with correct filename, you've to manage to have all parameters set correctly ('datas_fname' should set to real filename, etc.)

Fabien REMY
Penulis

Hi Temur !! Thank you very much for your reactivity and your great answer. Now it works. Once the file read in a local variable and encoded in base64, the file is stored with its data. Thanks again. Fabien.

Temur

Il n'y à pas de quoi

Fabien REMY
Penulis

Temur, One more question, regarding the mime type of my file. The module openerp.addons.document.content_index send an exception saying that it "Cannot determine mime type." Any idea ? Cheers.

Temur

try to add one more parameter (for csv file):

'mimetype': 'text/csv',
Fabien REMY
Penulis

You mean add that parameter when I create the ir.attachment object within the params dictionnary ? I've already try that, but it replies me that mimetype is not an attribute of that object.

Fabien REMY
Penulis

Here is the full stacktrace : 2015-05-11 13:48:13,480 5076 ERROR db_name openerp.addons.document.content_index: Cannot determine mime type. Traceback (most recent call last): File "D:\workspace_luna\openerp_server\openerp-7\openerp\addons\document\content_index.py", line 167, in doIndex pop = Popen(['file','-b','--mime',fname], shell=False, stdout=PIPE) File "D:\Python27\lib\subprocess.py", line 679, in __init__ errread, errwrite) File "D:\Python27\lib\subprocess.py", line 896, in _execute_child startupinfo) File "D:\Program Files\eclipse_luna\plugins\org.python.pydev_3.7.0.201408261926\pysrc\pydev_monkey.py", line 289, in new_CreateProcess return getattr(_subprocess, original_name)(appName, patch_arg_str_win(commandLine), *args) And a final error from Windows : WindowsError: [Error 2] Le fichier spécifié est introuvable = The specified file is not found

Temur

yes I meant to add this parameter when you create ir.attachment. agree, in v7 there is no mimetype field. I'm sorry, I actually work on v8 and in v8 there is mimetype field in ir.attachment model added somewhere. have not checked it back in v7. so 'mimetype' parameter is not a solution.

Temur

have you listed "document" module as dependency in __openerp__.py for your module? using 'depends' property?

Temur

custom indexer for csv fiels:

from document.content_index import indexer, cntIndex
....
class CsvIndex(indexer):
    def _getMimeTypes(self):
        return ['text/csv','application/csv','text/*']

    def _getExtensions(self):
        return ['.csv']

    def _doIndexContent(self, content):
        return content

cntIndex.register(CsvIndex())
your error comes from contentIndex.doIndex() function. it seems there is not support for indexing of csv files. you'll have to add support for it or install some module (if any) that adds such support. for the start you can try to add above custom indexer in your code. hope this'll work, if not, then you'll have to add support for indexing of csv files somehow if you want to disappear this error.
Fabien REMY
Penulis

Temur, ... you rock ! It works fine now. Thank you for your precious help.

Temur

You're welcome

Avatar
Temur
Jawaban Terbai

For datas parameter you'll need file content (encoded with base64).

Read the whole file content into the some varialbe, lets say _content, and then use as:

'datas': _content.encode('base64'),

 

3
Avatar
Buang
Temur

updated with .encode('base64'), as you read file content locally at the server side, it's normal content, whereas while sending over network content is encoded with base64 encoding. so after reading normal file content into the '_content' variable, you'll need to encode it witn .encode('base64') to get base64 encoded content string instead of normal file content string.

Avatar
Fabien REMY
Penulis Jawaban Terbai

Hi Temur,

No, the filename is encoded in a good way, just the file content (a "stupid" CSV file).

The fields "datas_fname" and "res_name" are OK. But the field file_size is not right (21 instead of 652 when I push it thanks to the graphical interface)

My question is, do I set the good type of object in the parameter "datas" ?

1
Avatar
Buang
Avatar
Fabien REMY
Penulis Jawaban Terbai

Hi Temur,

No, the filename is encoded in a good way, just the file content (a "stupid" CSV file).

The fields "datas_fname" and "res_name" are OK. But the field file_size is not right (21 instead of 652 when I push it thanks to the graphical interface)

My question is, do I set the good type of object in the parameter "datas" ?

1
Avatar
Buang
Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
Why does the filestore directory not appear after setting ir_attachment.location? Diselesaikan
filestore location ir_attachment
Avatar
Avatar
Avatar
Avatar
Avatar
14
Okt 24
48705
Upload Large File Store to Odoo.sh Diselesaikan
filestore
Avatar
Avatar
1
Jul 25
7770
where is the filestore folder located on odoo 18
filestore
Avatar
Avatar
1
Feb 25
5519
Clean up filestore
filestore
Avatar
Avatar
Avatar
Avatar
Avatar
5
Okt 24
14046
Create new bug
create
Avatar
0
Apr 24
2879
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

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