How to ForceDownload a file in OPENERP - odoo

I'm generating a pdf and storing it on my server using Openerp.Can any one please tell me how to Force Download that file using Openerp.If can upload the pdf using fields.binary and download it automatically.But i don't want to store the file in database.I want to directly download it.Can any one help me.Thanks in advance

I solved the issue by installing "Document Management System" module and attaching the files to "ir.attachment" instead of storing them as a binary field.Now you can download the document from the attachments.
code :
filename="/home/cryosave_qrcodes/xyz.pdf"
files = open(filename,'rb').read().encode('base64')
ir_values={
'name':image_name,
'datas_fname': image_name,
'type':'binary',
'datas':files,
'create_uid':uid,
'partner_id':ids[0],
'res_model':'res.partner',
'res_id':ids[0],
}
self.pool.get('ir.attachment').create(cr,uid,ir_values,context=context)

Fetch what file you want
use read and write function in python.
import os
path = os.path.join(os.path.expanduser(),('~'), 'documents', 'python', 'file.txt')
fh = open(path,"w")
fh.write("Hello World")
fh.close()

Related

After building an App(Android) using Kivy, Reading and writing text file(authorization completed)

I am using Filechooser, and checked whether the correct file is loaded using the print function until the data path.
text file name: A.txt
self.data_name = str(self.list_data_load.selection[0])
self.fdata=self.data_name
check_error= 'Path' + self.fdata
f=open(self.fdata,"r")
/emulated/0/data/A.txt
#F=f.readline()
but, when I try to use readlines, the app crashes and shuts down in Andorid.
I'm not sure if I need to grant additional permissions to read text files in external storage.
I need some help please.

nodejs npm libraries to access and modify microsoft word documents

Do you know if it is possible to search specific text like "xAx" into a Microsoft Word file (.doc or .docx) hosted on a website, replace it with some other text input by the user and make the file available for download using nodejs?
Is there a npm library that can do that?
If not it is possible to manipulate a PDF file instead? Please note that I do not want to create the document but manipulate a template file in the server.
Thank you for your help.
There is project https://github.com/open-xml-templating/docxtemplater which serves for replacing {placeholders} in a .docx files.
Also supports loops and images, check out demo (examples) on http://javascript-ninja.fr/docxtemplater/v1/examples/demo.html
If odt is an option (these files are open directly by MS Word besides Open and Libre Office and can be set with extension .doc so end users do not freak out) you can use HTML52PDF.
For example something like the following code will replace a string of text by a link:
require_once 'path/to/CreateDocument.inc';
$doc = new Html52pdf\createDocument(array('template' => 'template.odt'));
$format = '.odt';//.pdf, .doc, .docx, .odt, .rtf
//replace natural text
$doc->replace(array('replace me, please' => array('value' => 'external link')), array('format' => array('','')));
$doc->render('replaced_content' . $format);

In kettle use text file input read csv file from a tar.gz file but it didn't worked. Where it might be wrong?

I have a csv file that is tared and zipped. So I have test.tar.gz.
I would like, through text file input, read csv file.
I try this tar:gz:file://C:/test/test.tar.gz!/test.tar! use wildcard like ".*\.csv".
But it sometime can't read success.
It throws Exception
org.apache.commons.vfs.FileNotFolderException:
Could not list the contents of
"tar:gz:file:///C:/test/test.tar.gz!/test.tar!/"
because it is not a folder.
I use windows8.1, pdi 5.2
Where it might be wrong?
For a compressed file csv reading, "Text File Input" step in Pentaho Kettle only supports the first files inside the compressed folder(either in Zip/GZip file). Check the Pentaho Wiki in the compression section.
Now for your issue, try removing the wildcard entry since only the first file inside the zip/gzip file will be read. (as explained above)
I have placed a sample code containing both reading zip and gzip files. Check it here.
Hope it helps :)

How RApache force a pdf download by using R

i'm trying to using R and RApache to download pdf file with no success.
Here's my code
#R-Downwload pdf
#---------------------------------------------
pdf("/public_html/upload/rpdf.pdf")
attach(mtcars)
plot(wt, mpg)
abline(lm(mpg~wt))
title("PDF Report")
dev.off()
setContentType(type='application/pdf')
setHeader(header='Content-Disposition', 'attachment; filename=rpdf.pdf')
setHeader(header='Content-Transfer-Encoding', 'binary')
setHeader(header='Accept-Ranges', 'bytes')
cat("/public_html/upload/rpdf.pdf")
When I run this code on the browser, it show me the download popup box but when I click to download it display
... either not a supported file type or it has been damaged"
If you ever come accross this question, here's the answer.
setHeader(header='Content-Disposition', 'attachment; filename=rpdf.pdf')
setContentType("application/pdf")
t <- tempfile()
pdf(t)
attach(mtcars)
plot(wt, mpg)
abline(lm(mpg~wt))
title("PDF Report")
dev.off()
setHeader('Content-Length',file.info(t)$size)
sendBin(readBin(t,'raw',n=file.info(t)$size))
Enjoy!
You're printing out the string "/public_html/upload/rpdf.pdf" since it's in quotes. You want to print the content of the file, not the name of the file in your cat() call. Perhaps you could use write?

How can I allow more file extensions with drupal file uploads?

I've got a module that has to let users upload files and everything works as long as the files are in the standard array of allowed extensions. I've tried using file_validate_extensions, but this doesn't seem to change anything.
This is the code I'm using to upload now (the docx extension is added to the standard drupal allowed ones, but it doesn't seem to get picked up):
$fid = $form_state['values']['attachment'];
$file = file_load($fid);
if($file != null){
file_validate_extensions($file, "jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp docx");
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
}
I just looked to this Drupal API, and it seems that you can use the function "file_save_upload" (with $validator as an array of valid extension), this get the file in a temporary state. And then, you have to call "file_save" to make it permanent.