Hi,
I'm using atlassian-rest-common to upload a file from my confluence plugin, so this is what I have:
public Response uploadAttachment(@MultipartFormParam("file") FilePart filePart) {
// ...
Community moderators have prevented the ability to post new answers.
There is a getContentType() method on the FilePart parameter that will return the MIME type of the uploaded file. Here's an example REST resource to demonstrate:
import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import com.atlassian.plugins.rest.common.multipart.FilePart; import com.atlassian.plugins.rest.common.multipart.MultipartFormParam; @Path ("/test") public class TestResource { @POST @Path("/file") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.TEXT_PLAIN) public Response doStuffWithFile(@MultipartFormParam ("file") FilePart file) { return Response.ok("You uploaded a " + file.getContentType() + " file").build(); } }
And the HTML form that submits to it:
<form method="POST" action="$req.contextPath/rest/module/1.0/test/file" enctype="multipart/form-data"> <div class="field-group"> <label for="file">File</label> <input class="file" type="file" name="file" id="file"/> </div> <input type="submit" class="submit" value="submit"/> </form>
Damn, the documentation that pops up in google when you look for com.atlassian.plugins.rest.common.multipart.FilePart is https://docs.atlassian.com/atlassian-rest/1.0.0/atlassian-rest-common/apidocs/com/atlassian/plugins/rest/common/multipart/FilePart.htmlso I didn't bother, sorry :<
Thanks for the quick answer thought!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, that's an easy mistake to make! Some of the docs are on docs.atlassian.com and other docs are on developer.atlassian.com/static. It looks like the newer versions of atlassian-rest-common docs are on the latter.
It looks like the getContentType method was added in version 2.x - https://developer.atlassian.com/static/javadoc/rest/2.5/reference/com/atlassian/plugins/rest/common/multipart/FilePart.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.