My application has a mechanism in exporting and importing a json file. Exporting will happen after clicking a link. The exported file have a default ".action" extension since the link is mapped to an action.
How to change the file extension automatically to ".json" since importing requires ".json" extension?
Im using this result type
<result-type name="json" class="com.googlecode.jsonplugin.JSONResult" />
Normally you submit a form and the values are mapped onto the object, when using the json plugin you return a json string for ajax use... if you are really sending a file or returning a file then the content of the file has little to do with the issue.
See here for downloading a file with struts2: File download using Java, Struts 2 and AJAX
Related
API call for download a file which is csv is giving good repsonse in Tree listeners. I have save the downloaded file using save response to a file listener using prefix with name.csv.
But on chcing in bin folder of jemter the same csv seems to be 0 bytes. whereas in tree listeners i can see repsone.
what should i do to get the same data in csv file too.
enter image description here
Most probably you're looking at the wrong file. If you want the result to be saved as CTCbreakup.csv you need to use the following configuration of the Save Responses to a file listener:
Default configuration will give you something like CTCBreakup.csv1.octet-stream
More information: JMeter Performance Testing: Upload and Download Scenarios
Invalid Stream header Error in WEKA - CSV Loading
Unable to load simple CSV file in weka
In the Experimenter->Datasets-> Use relative path (check this box)
From the error message, it looks like you clicked on Open... in the GenericObjectEditor window instead of OK to accept the configuration of the CSVLoader class to load your CSV dataset.
The Open... and Save... buttons are for loading/saving object templates, not for loading/saving the CSV file (you are in the process of loading a CSV file, so a Save button makes no sense for this operation).
With this template functionality, you can maintain a library of commonly used setups for any Weka object (loader, saver, filter, classifier, etc.) and simply load it back into the GenericObjectEditor when you need it.
There is a file input that is used to upload csv files.
Here is the documentation for multipart file class.
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/multipart/commons/CommonsMultipartFile.html
Now i would like to make sure the uploaded file is csv file. In other words the application only accepts csv files. There are two methods that commonsmultipartfile class offers. One is contentType. For csv file it returns application/octet-stream. Another method is originalFilename which gives the filename with extension.
So i am wondering what is the best way to make sure the uploaded file is csv file. My doubt is that checking contenttype is not enough since application/octet-stream is mime type for binary file. So do you recommend using both contenttype and originalfilename to extract the extension. I appreciate any guide. Thanks! I am using grails 2.2.
You can prevent anything other than files with a .csv extension being uploaded with the accept attribute e.g.
<input class="form-control" required="required" type="file" name="csvfile" id="csvfile" accept=".csv" />
This doesn't prevent someone changing the extension on e.g. an xslx file and attempting the upload however, I tend to parse a row or two while streaming the file and reject it if it doesn't match the pattern I'm expecting.
Of course this may not be practical for your solution.
i want to handle a requirement in polymer webcomponents where user can upload csv file from ui and csv file can be parsed to json and sent to server ,i searched and found for vaadin upload,looked over the api but i am not sure how to receive the csv file and convert to json and sent to server,can anyone show a jsfiddle of vaadin upload or any other web component to handle this scenario?
First of all, I am wondering why you would not simply do the conversion on the server side.
In this case, you would be able to use the vaadin-upload directly indeed.
Here is a snippet that would upload all files to the example.com server, and only allow CSV files.
<vaadin-upload target="https://example.com/upload" method="POST" accept="text/csv">
</vaadin-upload>
There are plenty of resources on how to convert CSV files to JSON.
Here is a snippet
And here is a node library
If you really wanted to do the conversion client side, then I would suggest to create an element that would embed a vaadin-upload, and convert the Files array to Json before manually calling the uploadFiles method.
I have some generated .html reports in a folder and want to convert multiple .html, .css, .js and image files into one report.mhtml file so that single file can be accessed as a web service.
Is there any Java API to convert the folder of .html files to a single .mhtml file?
I was investigating the reverse (unpacking an MHTML/EML to files) and while there didn't seem to be a simple Java-based utility to do this, I found the Apache Mime4J libraries to be very useful (and easier than JavaMail).
You can find the code I shared here: How to read or parse MHTML (.mht) files in java
For your case, to build an MHTML, if you can't find anything simpler, approach could be:
Create a Message object which has a Multipart body.
Read all files in a folder using Streams, append these as BodyParts of the Multipart with their mime-type (Mime4j includes a Base64 stream encoder/decoder).
Ensure the references in the html page point to the necessary body parts (may be able to embed their original filename as reference?).
Write the Message object to mht file or a response stream.