How to make client download xml file from server? - java

My server is implemented with few servlets when each one is responsible for different task.
I need to make client to download a specified xml file from server when a SAVE button in html page pressed.
I've read that the best way is to host file on server and just let client download, but I don't know how to implement it.
Any example will be highly appreciated. :)
p.s.
I'm using JAVA.

Do these steps:
Set proper MIME-type for your file. If you do not want (there's no suitable MIME-type) to set MIME-type specific to your file type, then set it to application/octet-stream
Set content length to the response
Set content disposition
Open output binary stream, then read your file and write its contents to this output stream.
That's it.
Here is the sample code

Related

How to change attachment of Outlook .msg file with Apache POIFS/HSMF

I am working on some project that requires changing attachments of an Outlook .msg file.
I chosen to use Apache POI with its low-level POIFS API.
I am able to substitute binary data of an attachments by re-writing PR_ATTACH_DATA_OBJ ByteChunk, as well as few other Chunks related to filename, extension, displayName.
However, when I open the resulting .msg file in outlook my attachments viewed as no-extension file but content is exact what I have pushed to it:
There are two more fields that I can't find possible data to write as well as there is no description for them in MAPIProperty.Java POI dictionary:
Can somebody advice me how I can make attachment substitution possible to success? What kind of data I have to put into these two fields in order to fix preview? Will this help?
I am looking for a free solution. I already tried Aspose.Email and this works brilliant but it is not currently an option.
Embedded message attachment (stored in PR_ATTACH_DATA_OBJ property on an attachment) is not a file.
Does Outlook correctly open the attachment? Make sure the attachment type remains the same.

Java Servelet 3.0 File Upload to input stream - without intermediate folders or files being created

I dont know how to do this, or whether is possible or wise, so any form of answer that points me to a library, example or reasoning will be helpful.
I need to upload and process some Java XML files (actually, XSLT files - XML Excel files).
I dont want to store the file on the server and then invoke processing on it. Instead, I want to stream the file in, and process it as a stream.
I also want to be able to process multipart file uploads, but still process that as an input stream.
I am expressly trying to avoid creating a file on disk for this.

Starting HTML/CSS/Javascript file from Java

I have written an Java code that process some data and stores it in .JSON format.
I also have HTML/CSS/Javascript file, that reads that data, and shows it in much nicer way.
So my question is, is it possible to combine Java and HTML code(in one file .jar) so that, for example on a click of a mouse Java opens HTML file in Default browser?
Thanks
Write out the html file to the filesystem (e.g. a temporary directory How to create a temporary directory/folder in Java?) and then open it using the default program: How to open a file with the default associated program

How to add a custom tag to a file (mostly images) which is uploaded to a server, and the tag is read through a php script to sort it?

When a file is uploaded to a php server, I am trying to figure out a way to get files sorted. What I want to do is add a custom tag to each file programmaticly in android, upload it to the server (which I have alreay done), and read that tag through a php script.
Thanks for the help
Exif seems to be the way to go for adding metadata to an image. See this related question.
I actually don't think this is the best way to solve you problem. You shouldn't modify the physical image just to introduce some ordering. What exactly do you want to accomplish? You just want to have the same order on the server that you had on the device? What about you send the order in a separate piece of data, say JSON or so?

Downloading a file to modify it on Amazon S3

So I am using S3 to store basically audio files, I stream those files with cloudfront. I need to modify the metadata of those files (not the metadata of the s3 object, but the tags of the music), or convert those files to another format (mp3 to m4a, etc). So the way I see it I need to download these files to my server, modify the files or transcode this files, and reupload the files.
I see some ways to do this but I have some doubts on which is the correct way or best way to do it.
So one way would be to download the file with the following code
S3Object object = s3.getObject(new GetObjectRequest(bucketName, key));
System.out.println("Content-Type: " + object.getObjectMetadata());
//displayTextInputStream(object.getObjectContent());
And I could use File to write the file to my server.
My question heres is how do I obtain just the file name from the S3Object, I was looking in the metadata and tried to use getContentDisposition(), but it returns null, looking directly in AWS Console I see the proper name of the file without the path.
The other idea I have is to use cloudfront to download the file, creating a download distribution.
Can I work directly with and inputstream to modify the metadata?
You can save this file under any name you choose, just like any other file you download through HTTP.
However, as you mentioned in your question:
String disposition = object.getObjectMetadata().getContentDisposition()
Should give you the optional Content-Disposition HTTP header, which specifies presentation information for the object such as the recommended file-name for the object to be saved as.
This function returns null if the Content-Disposition header hasn't been set.
This is from Amazon online documentation: For more information on how the Content-Disposition header affects HTTP client behavior, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1.

Categories

Resources