Hi, I am developing a plugin that allows you to bulk create users on a server based on the data in a csv file. I've managed to get a velocity template showing with a form, as such:
<form id="form" action="#">
<label for="file-input">Choose CSV file:</label>
<input type="file" id="file-input" name="file-input" accept=".csv">
<button type="submit" value="Submit">Submit</button>
</form>
However, I'm stuck on the action java class. How do I handle the csv file upon submitting the form (extract the data from the csv file)?
You form needs to be
enctype="multipart/form-data"
And your action should implement "ServletRequestAware"
And you should receive a "MultiPartRequestWrapper" really into your action class (injected by xwork framework)
Then it is a matter of simple calls to "MultiPartRequestWrapper" instance to get uploaded file(s). I am pretty sure you can figure out the rest
Alex
Hey Alex, thanks for replying!
It says here that ServletRequestAware is deprecated. I'm guessing I should do something like the answer in this question?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, you can use
ServletActionContext.getRequest();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alex, I've tried following this solution but I still can't get it to work. It just refreshes my page and nothing is logged. What could be the issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your "action" attribute should point at the action (class mapping) that handles the upload... not at #
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for replying Alex. The action attribute of the form does point to the servlet class.
Form from Velocity template:
<form class="aui" id="form" enctype="multipart/form-data" method="POST" action="${req.contextPath}/my-servlet">
<label for="file-input">Upload CSV file:</label>
<input class="upfile" type="file" id="file-input" name="file-input" accept=".csv">
<button id="submit-btn" type="submit" value="Submit">Submit</button>
</form>
atlassian-plugin.xml:
<servlet key="my-servlet" class="com.dso.intern.plugin.MyServlet" name="Bulk User Creation Tool Servlet">
<description key="my-servlet-description">#</description>
<url-pattern>/bulk-user-creator</url-pattern>
</servlet>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First of all the patterns dont match ("my-servlet" vs "/bulk-user-creator") and second, is that the mapping to servlets declared in plugins starts with
/plugins/servlet/
Check Atlassian documentation on this...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.