Reputation: 65
I'm trying to add upload attachment in my Corda application but it's not working as I'm getting below error at start up itself.
[[FATAL] No injection source found for a parameter of type public javax.ws.rs.core.Response com.test.agreementnegotiation.api.AgreementNegotiationApi.uploadFile(java.lang.String,java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition) at index 0.; source='ResourceMethod{httpMethod=POST, consumedTypes=[multipart/form-data], producedTypes=[], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class com.test.agreementnegotiation.api.AgreementNegotiationApi, handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@14ab26a]}, definitionMethod=public javax.ws.rs.core.Response com.test.agreementnegotiation.api.AgreementNegotiationApi.uploadFile(java.lang.String,java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition), parameters=[Parameter [type=class java.lang.String, source=tags, defaultValue=], Parameter [type=class java.io.InputStream, source=file, defaultValue=null], Parameter [type=class org.glassfish.jersey.media.multipart.FormDataContentDisposition, source=file, defaultValue=null]], responseType=class javax.ws.rs.core.Response}, nameBindings=[]}']
Below is the code -
@Path("upload")
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@DefaultValue("") @FormDataParam("tags") String tags,
@FormDataParam("file") InputStream file,
@FormDataParam("file") FormDataContentDisposition fileDisposition) {
String fileName = fileDisposition.getFileName();
saveFile(file, fileName);
String fileDetails = "File saved at " + UPLOAD_FOLDER + " " + fileName + " with tags "+ tags;
System.out.println(fileDetails);
return Response.ok(fileDetails).build();
}
private void saveFile(InputStream file, String name) {
try {
/* Change directory path */
java.nio.file.Path path = FileSystems.getDefault().getPath(UPLOAD_FOLDER + name);
/* Save InputStream as file */
Files.copy(file, path);
} catch (IOException ie) {
ie.printStackTrace();
}
}
I searched on error and found that we need to enable/resgiter MultiPartFeature.
Whatever link I found they talk about changing web.xml or adding AppCong and I'm Not sure how it can be done in Corda sample project.
Corda team please help.
Upvotes: 0
Views: 365
Reputation: 36
The endpoint of the deprecated webserver /upload/attachment
does not work anymore in corda V4
Upvotes: 0
Reputation: 23150
The built-in node webserver has a default endpoint for uploading attachments, /upload/*
. This endpoint is available out-of-the-box and does not need to be added in your API. You upload an attachment by making a POST request to this endpoint with the encoding type multipart/form-data
.
For example:
<form action="/upload/attachment" method="post" enctype="multipart/form-data">
<div class="form-group">
<input type="file" name="jar" class="form-control">
</div>
<br>
<button type="submit" class="btn btn-default">Upload blacklist</button>
</form>
You cannot provide your own additional endpoints for uploading attachments.
If you write your own node webserver (e.g. a Spring webserver), then there are no limitations.
Upvotes: 0