1

Currently, I can upload files(exist) with Grails's RestBuilder. However, I want to upload a file without creating a file . I want to create binary data (= Text File) in a program and send it directly Is it possible?

RestBuilder rest = new RestBuilder()
RestResponse resp = rest.post(url){
    contentType("multipart/form-data")
        setProperty("dataFile",[filePath])// <- it can
        setProperty("dataFile",[ byte[] or inputStream() or String ? ])// <- Is it possible?
}

'''

1 Answer 1

1

I'm sure you figured this out already, but you can just use a String reference or a byte[] just as you can use File instances for the multipart request using RestBuilder. It should 'just work' e.g.

RestBuilder rest = new RestBuilder()
RestResponse response = rest.post(url) {
    contentType 'multipart/form-data'
    stringPart = 'hello' // String
    bytePart = '68656c6c6f'.decode64() // byte[]
    filePart = new File('/path/to/file.jpg') // File
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.