Is there any chance I can open or save an existing file after clicking a link from an xpage?
My scenario: A link to an attachment ( an excel file ) so all users when clicking the link, they will have the possibility to open or save the file.
My app works both on Lotus Client and web.
Thanks for your time
I assume (from your comments) that you are looking for a way to store one certain Excel file somewhere and to give users access to this file with a link.
You can achieve that this way:
Store your Excel file in your database at Resources / Files (e.g. as "sample.xls")
Create a link in your XPage pointing to this file just with the name (e.g. "sample.xls")
<xp:link escape="true" value="sample.xls">Excel sample file</xp:link>
Users can open or download this file in browser or XPiNC clicking on link.
You need to set proper content type. For an existing file you would need to make your own service (XAgent) to alter it. Or you can try to set it for the link.
And bear in mind, that action associated to content type is configured in browser - so every user has it's own.
If you just want to make the file available normally, Knut's answer is about what you want: store the file as a File Resource in the database and link to it on the XPage. I would add one adjustment, though: start the URL in the "value" property with a "/", e.g.
<xp:link value="/sample.xls" text="Excel sample file"/>
The reason for this is to ensure that the generated link is always relative to the NSF, not the XPage - without it, you'd have a problem if you open the XPage with a link like "/someView/someDocKey" (with display-XPage-instead in the form) or if you happen to include extra path info after the XPage (e.g. "/foo.nsf/somePage.xsp/some/path/info").
But if you mean that you want to cause the browser to display the Save File dialog instead of whatever its normal behavior would be (e.g. IE opening the Excel file in the window), the core of the solution is the Content-Disposition header. If this header is set to tell the browser the file is an "attachment", then the browser will prompt the user (or do whatever its normal file-download routine is) instead of opening inline.
Depending on how the file is stored, the solution will either be fairly easy or not-impossible-but-sort-of-a-pain:
If it's a file attached to a document, I believe that the normal control generates links to an attachment-download service that adds this header normally.
If it's not (e.g. it's a file resource), then Frantisek's advice comes into play: you'd have to write your own shim XAgent or servlet that writes this header and then spits out the file's contents.
While the latter is doable, it's a pain, and so I'd suggest trying to wrangle your attachment into a normal document if at all possible. For example, if it's attached to a document in a hidden view, you could do something like:
<xp:panel>
<xp:this.data>
<xp:dominoDocument var="attachmentDoc" action="openDocument" ignoreRequestParams="true">
<xp:this.documentId><![CDATA[${javascript:
database.getView("SomeLookupView").getFirstEntry().getUniversalID()
}]]></xp:this.documentId>
</xp:dominoDocument>
</xp:this.data>
<xp:fileDownload value="#{attachmentDoc.Body}"/>
</xp:panel>
Related
Hello I'm making a website and I want that an user can edit some of the texts content in the website, clicking a button "Save" and the changes are permanent.
I suppose I have to put all the text in a database instead of keeping it in html code, but this will slow down the website loading performance.
Is there a library to easily achieve this functionality? Pheraps changing html code instead of acting on the database.
You have to read the file content and load it into a form in a textarea or WYSIWYG and after submitting the form, put the changed data back into the file. The codes for loading and saving data, depends on programming language. check the documentation for opening and saving the file in PHP here.
http://php.net/manual/en/function.file-put-contents.php
First of all i work with Drupal 7.
I have a custom content type which allows me to upload an audio file.
I found a way to play the audio file when the user access a page of this content type.
Now i want to let the user download the audio file, but not remove the play capabilities. I want to add a download button on the same page (details page of the content type).
Can someone explain me how to do it ? I've got nowhere on this matter.
There are many ways to achieve this, depending on your drupal expertise. If you are using node templates, then you can print the same variable twice, once inside the music player plug in, and once with a download button. Something like this:
...... prints other fields .....
<my-audio-player src="<?php print $node->field_my_audio_field;?>"/>
Click to download
...... prints other fields .....
To force the download instead of opening, check this: Force browsers to download a file rather than open
To achieve this without writing any code or templates, you can do what Fleix Eve have suggested above. Set the display settings as direct download. Then create a block view which shows your audio file field, take the argument from URL. Then set tat block to display on node-view.
I have created a file upload function which saves all the uploads to a certain place:
private String destination = "D:/Documents/NetBeansProjects/FileUpload/uploadedDocuments/";
Is this a good place to store it? Should I store it some where else?
Is it possible that once the upload is complete for a page to be displayed showing the user what they have just uploaded, like a box below showing a preview? And how would I go about doing this? I am new.
I have figured it out how to display a plain txt file and an image, however it is the pdf that is confusing me.
As to the upload location, which seems to be the IDE project folder, that's absolutely not right. You should choose a configureable and fixed location somewhere outside the IDE project folder. You should not rely on using getRealPath() or relative paths in java.io.File. It would make your webapp unportable. See also this related question: Uploaded image only available after refreshing the page.
Whatever way you choose based on the information provided in the answer of the aforementioned question (and all links therein), you should ultimately end up having a valid URL pointing to the PDF file in question such as http://example.com/files/some.pdf.
Then, you can serve the PDF file on a webpage using either an <iframe>:
<iframe src="/files/some.pdf" width="600" height="400"></iframe>
Or an <object>:
<object data="/files/some.pdf" type="application/pdf" width="600" height="400">
some.pdf <!-- This link will only show up when the browser doesn't support showing PDF. -->
</object>
Keep in mind that showing PDFs in a browser is only supported in browsers having Adobe Reader plugin. Note that the <object> approach will gracefully degrade to a link when the browser doesn't support displaying application/pdf content.
I'm a coldfusion developer working on a reporting application to display information from a CFSTOREDPROC process. I've been able to get the data from my query to display correctly in a CFGRID, and I'm really happy with the display of the data. The grid saves a lot of time because it avoids using the CFOUTPUT tag and formatting the data in HTML for hundreds of reports.
All I would like to do is add a simple Disk Icon somewhere on the datagrid control that would save the contents of the datagrid and export it into an XLSX(2010) file that an end user could then manipulate in a spreadsheet program. This is important because the data needs to have a 'snapshot' at certain times of year saved.
Solutions Tried:
I looked into having a link from the report options page that would fire into a report_xls.cfm page but designing a page that catches all of the report options a second time seems dumb and would add thousands of CFM's to the website.
CFSPREADSHEET seems not to work for a variety of reasons. One is that the server seems to constantly fight me with the 'write' function in this tag. Another is that I don't know how to make the javascript work for this button to get the output that I want.
I also looked into doing this as a Javascript button that would fire based on the data entered. Although the data from a CFSTOREDPROC will display correctly if I use a CFOUTPUT block, CFGRID seems to have a hard time with all output styles except HTML. This has caused some difficulty with these solutions because the application doesn't spit out a neat HTML table but instead sends a javascript page section.
Raymond Camden's blog contains an entry Exporting from CFGRID that we used in our project.
The example in the article exports to PDF, but it is rather simple to modify the download.cfm file to export to Excel files as well:
You modify the file to generate the <table>...</table> HTML from his example in a <cfsavecontent variable="exportList"> tag, so that the #exportList# variable contains the table that will be shown in the spreadsheet.
Next we have a URL parameter mode that determines whether it is exported to PDF or Excel.
So the end of our download.cfm looks like the following:
<cfif url.mode EQ "PDF">
<cfheader name="Content-Disposition" value="inline; filename=report.pdf">
<cfdocument format="pdf" orientation="landscape">
<cfoutput>#exportList#</cfoutput>
</cfdocument>
<cfelse>
<cfcontent type="application/vnd.ms-excel">
<cfheader name="Content-Disposition" value="report.xls">
<cfoutput>#exportList#</cfoutput>
</cfif>
I'm trying to build a chrome extension that overrides a download of a file and displays it in the browser. For example if you click on a link to a '.csv' file I'd like it to render in the browser instead of downloading it.
Chrome already does it for PDF's types and the Xml Tree extension also does exactly that for xml files.
So it should be possible, just not sure how to go about catching that event?
An implementation along the lines indicated by in the previous answers and specifically designed for CSV files can be found in this extension of mine on github:
https://github.com/rgrp/chrome-csv-viewer
Furthermore, with the new(ish) chrome webrequest API a direct approach is also now possible along the following lines:
Listen to onBeforeRequest (this has to be in a background script - see background.js)
Check if this is a CSV file (mimetype or file extension)
If so cancel the request and then display the data using xhr
A working version of this can be found in a branch of that extension: https://github.com/rgrp/chrome-csv-viewer/tree/4-webrequest-intercept
You could always look at the XML Tree code :).
If you only need to work with links, and not opening files from the address bar or File > Open, you could build a content script that adds a click event listener to every link.
In the event listener function:
Add e.preventDefault() in the first line to prevent the browser 'following' the link.
Using the link href value, get the data with XMLHttpRequest.
In the XMLHttpRequest callback, open a new tab and render content accordingly.
Obviously, in many ways, this is not a great solution:
you want 'normal' links to be handled as usual by the browser
how can you tell if a text file contains comma-separated values (for example) except by looking at the file extension which, of course, may not be reliable?
Are you specifically thinking of .csv files -- and/or other specific types of content?