restlet / restlet-framework-java

The first REST API framework for Java
https://restlet.talend.com
646 stars 284 forks source link

Restlet client to upload file into non restlet rest endpoints #1379

Open Murugesh-G opened 3 years ago

Murugesh-G commented 3 years ago

I am trying to create rest client by using restlet library [ This client is to upload file in way of multipart/formdata],

try {
            Representation file = new FileRepresentation(new File("/home/user1/data2.xml"),
                MediaType.APPLICATION_ALL_XML);
            FormDataSet form = new FormDataSet();
            form.setMultipart(true);
            form.getEntries().add(new FormData("upload_file", file));
            ClientResource cr = new ClientResource("http://localhost:8080/upload");
            cr.post(form);
        } catch (Exception e){
            e.printStackTrace();
        }

The following above code works fine for restlet based rest provider but not for third party rest provider [ like spring boot rest endpoint which accepts post for multipart/form-data], Could anybody help here to resolve the issue?

The error I get as follow

Bad Request (400) - The request could not be understood by the server due to malformed syntax
    at org.restlet.resource.ClientResource.doError(ClientResource.java:590)
    at org.restlet.resource.ClientResource.handleInbound(ClientResource.java:1153)
    at org.restlet.resource.ClientResource.handle(ClientResource.java:1048)
    at org.restlet.resource.ClientResource.handle(ClientResource.java:1023)
    at org.restlet.resource.ClientResource.post(ClientResource.java:1485)
cyberquarks commented 3 years ago

@Murugesh-G Perhaps you can share your code here: https://gitter.im/restlet-framework/community?utm_source=share-link&utm_medium=link&utm_campaign=share-link