I've got a smartgwt application which create a link with a jpg/gif/png/pdf files. This files are shown in browser. I want to get the save dialog instead it which ask me the path when I want to save the file at local machine. How could I do that?
As I know, you have to change the response header by setting the Content-disposition to attachment. Like this:
'Content-disposition: attachment; filename=image.jpg'
'Content-type: image/jpeg'
With these the browser will understand most cases that it should show up a dialog to save the image with the name: image.jpg. Also it might offer you to send it directly to an application, for example to an image viewer.
To get it work from a simple link, perhaps you have to write a servlet which will return the requested file with the correct headers and call that servlet from every link with a parameter to the real file.
Related
I have .vm file for confirmation order mail and I'm placing some informations to this .vm template. There are several images in these informations. But my images not rendered while the email was sending.
I tried several methods but doesn't work.These are:
<img src='${ctx.contextPath}/images/theme/social_01.jpg
<img src='${ctx.themeResourceUrl}/images/theme/social_01.jpg
and
<img src='../images/theme/social_01.jpg
Any one of these are didn't work for me.
Also my images at the following location of the project:
xxxStore > import > sampledata > contentCatalogxxx > images > theme >
How can I solve this problem ?
Can you print the complete image URL in the email and try to open it in the new browser window and see. You should able to access your image. If not, try looking at the URL, is it correct? Let me know the result.
I would suggest you to following any exiting working image, place your image to the same folder, and access it similarly.
It seems you are trying to access static image. You can find all frontend static content under the webroot folder of the storefront extension. Your image should be in the same folder as well.
e.g.
I have an image at
sastorefront/web/webroot/_ui/responsive/theme-blue/images/test.png
I can access it using
${themeResourcePath}/images/test.png
To debug path issues, I would print the path, and try hitting same URL through the browse. Ideally, an image should be accessible with the URL. Say in my case, I can access test.png with
https://example.com/_ui/responsive/theme-blue/images/test.png
You have to make sure that your image URL which you are using in VM is corresponding to the actual image URL.
To provide this,
go to Backoffice media type
check your media URL
I'm working on a web application at the moment using Tomcat and spring framework. A CSV file is stored on the server, the path to the file and the filename is stored in the database.
A search button on a webpage would list all records in database, if user click on one listed item, a saving dialog would be displayed and the file will be saved locally.
I want a dialog like this opened when user click on one item, how can I do it with httpServlet? I can think about a solution is set content-disposition type in response header to 'attachment'. It would force the browser to download the file instead of trying to display it in browser. But I want user to be able to select the type for file download. Please take a look at the image below
Setting the Content-Type response header to something that the browser is unable to render should prompt the user to save the file upon receiving the response. A value of application/octet-stream (arbitrary binary data) should do the trick.
However, since you expect the actual file content to be in different format depending on user choice, here's what you would need to do:
create a link/form on your html page that will allow user to select a type and make a request to URL with proper extension (like download/file.xls for XLS or download/file.csv for CSV).
in your servlet that handles these URLs, check the extension requested (easy) and then convert the file to expected format within your servlet (not so easy) and send it in response.
The scenario is like : I have a page on which when we submit a file number, the client is given a link to download the file. But I don't know how to write one servlet which will decide which file to send to the client. This has to happen on clicking of a link, so I can't send parameters which can help me determine which file to download.
Please help.
you submit a file number;
you build a link based on that file number (it's a link for a GET. GET can have parameters, so you can put parameters in the URL path or in the query string);
user clicks the link;
the link is handled by a servlet;
the servlet uses the parameters from the GET request to determine what file to send;
you send the content of that file in the response.
Those are the steps.
Here is an example on BalusC's blog: http://balusc.blogspot.ro/2007/07/fileservlet.html
What you need to take care of is security:
don't expose the file directly as path on the server otherwise users can navigate the path to access other files on your application;
if users of your application have different rights, make sure you check those rights before returning the file, so that you a user can't access somebody else's files.
I am rewriting some code that used to use GET and replaced it with POST.
The download URL used to be a GET request to
https://myurl/getfile?fileid=1234&filetype=pdf
Now, I changed that to
https://myurl/getfile
and put the fileid=1234&filetype=pdf in the POST body.
I did this using jquery's post method as:
function postCall(url, param) {
$.post(url, param);
}
The server side is written using Java and I tried to reused the old code for GET, which write the file binary into the servlet's stream.
However, my browser does not prompt user for download, which used to do for GET.
Previous posts on stackoverflow did suggest that AJAX should not be used for file download. But what is the alternative way for me to use? The request is not generated by a form though.
Many thanks.
I would suggest creating a form on the page (or create one dynamically using jQuery), and then have that form do the post submission (using jQuery's "submit" function or "trigger('submit')" on the form). This way the request won't be done asynchronously in the background. If the "getfile" script responds with a file with Content-disposition: attachment, it should download.
That said, I'm not sure the browser will "prompt" the user in this scenario--this is dependent on the browser (whether or not a dialog appears to save the download, or if it automatically downloads the file without a prompt).
I have a Java project upload functionality which is uploading image onto the server location C:/temp and I want same image to show on UI as soon as uploaded but the problem is when i am passing image path(C:/temp) into JSON then then system is reading that image path relative to project and getting an error
(NetworkError: 404 Not Found - http:// localhost:8080/group/images/c:/temp/Jellyfish.jpg")
because file is present in C:/temp. What would be the possible solution of this. please help me guys?
Thanks,
Ankit
You need a servlet that will read the file from c:\temp, and send the read bytes to the servlet's response output stream. You will also need to set the content type of the response to the mime type of image you're sending (image/png for example), and the content length to the number of bytes in the file.
And this is the URL of this servlet that you will have to pass into the JSON object.