Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Murugesh-G opened this issue Feb 24, 2021 · 1 comment
Open

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

Murugesh-G opened this issue Feb 24, 2021 · 1 comment

Comments

@Murugesh-G
Copy link

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

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants