java open a file(pdf,xsl,etc...) from mongo db - java

I have files(pdf,doc,txt,xsl,etc..) stored in my mongo *db*. I want to retrieve and open them. I know to extract. Also I found out that Desktop.getDesktop().open(FileName); will open the file with its respective application(Acrobat reader, office suite etc). But can anyone please tell me if only the file would be enough or we should give the full path for the file.
In the latter case, can anyone plesae tell me how I could path for the file which is being retrieved from mongodb?

You'll have to extract the file from Mongodb if you want to open it using Desktop.getDesktop().open(FileName);
You can create a temp file using File.createTempFile and write in it the content fetched from mongodb, with the correct file extension, and then run Desktop.getDesktop().open() to open it.

Related

What is the best format for transferring RTFs from a server to a local RTF editor?

I know that I can use a BLOB or an XML file, but I was wondering if there was a better way to do this, or if either of these are the correct way of doing this. The user should be able to edit their file online and then save it onto the server, and at any time get the file back into the editor and continue editing that file (similar to that of Google Drive). Any ideas? We are using Spring Framework and controllers for our site. We are using a MongoDB for file storage (files are stored on the server, file paths are stored on the MongoDB).

Alfresco File Storage(alf_data)

I am in an situation where i need to run one command-line tool for file which is uploaded in alfresco repository.The reason behind this is i need to perform OCR on that particular file.
I know i can use transformation which alfresco by default provides.But transformation does not provides conversation between same mimetype and my requirement is like performing OCR on PDF File(which contains images) and again generate PDF File(Which contains extracted data).
My approach is to create a policy, when node is uploaded in alfresco repository.
From that policy I will access the node which is uploaded in alfresco repository using java,Here is the problem ,I dont know under which location of alf_data directory the file is getting uploaded.As i need to get physical location of file.
By the way I am using linux system.
Can any one help on this?
You need to use the ContentService, specifically getReader(NodeRef,QName) then getContent(File) to a temporary file
Your code would then be something like
File tmp = File.createTempFile("for-ocr",".tmp");
ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
reader.getContent(tmp);
// Run the OCR program here
tmp.delete();

Any Java plugin/code to manage uploaded files?

According to current requirement,user will upload files with large size,which he may like to download later. I cannot store the uploaded files in DB because the size of files is large and performance will be impacted if I store uploaded files in DB.
Any one knows any java plugin which provide efficient file management on webserver and maintains the link to file so that the file can be downloaded when the link is requested. Also the code will make sure that user will be able to download only those files which is uploaded by them,they cannot download any file just by modifying the download link etc. I am using spring3 as the framework.
Please suggest how to solve this problem?
if you have write access to the file system why not just save them there ?
you then generate an unique ID and save the hash/file relation in db, you then need to supply the ID to get the file feed from a servlet
Store the file content on a part of filesystem out of web application so you cannot reach it changing the link.
Then you can store on db the path for that file, and return them only if the user has the permissions to read it.
Pay attention, do not store all the file on the same folder, or the number of files could grow too much. So find a way to store them with more folder levels.

How to read .rpt files and load data to database

I need to read .rpt files and load the data into MySQL or Oracle using Java.
Can anyone help in this?
As far as i know, .rpt files are used by BIRT.
Are the .rpt (report) files processed in any way or do you just have to write them into a database?
In case of the latter, the necessary steps are:
Create a list of all .rpt files
For each of the files:
Read the file into a String
CREATE a SQL INSERT statement and execute it against your database
Profit.
I will expand this answer if you clarify your requirements.

How to check whether the uploaded file is XLS file or not?

I have a file uploader module. The UI is created using simple HTML and Javascript.
Server side I am using Java code. I want to check the type of the uploaded file.
Files don't really have types. The best you can do would be to attempt to load the file as an XLS.
If the load succeeds, the file is most likely an XLS.
If the load fails, the file is either an invalid/malformed XLS, or not an XLS at all.
You can also look at the uploaded file name or the content type, but neither of these is definitive; i.e. they might say that the file is an XLS when it is something completely different.

Categories

Resources