Comments (3)
From @slackfarmer on February 28, 2015 0:7
I figured out how to do it, by using an apache library(MultipartEntityBuilder) to compose the multipart body.
Added apache mime dependency
dependencies {
compile('org.apache.httpcomponents:httpmime:4.4')
...
Body Building Code Sample
returns end point and a byte array
public static Map getTestAssetProperties(String assetName){
String destPath = "${REPO_TEST_ASSET_PATH}${assetName}"
String endPoint = "/api/repo/upload/${destPath}"
File asset = new File("./src/test/resources/${assetName}" as String)
MultipartEntityBuilder e = new MultipartEntityBuilder()
e.setBoundary("fnord")
e.addTextBody('filename', asset.getName())
e.addBinaryBody("fileUpload", asset)
ByteArrayOutputStream baos = new ByteArrayOutputStream()
e.build().writeTo(baos)
return [endPoint:endPoint, bodyInBytes: baos.toByteArray()]
}
Spock Test Example
Notice content type settings: ['Content-Type': 'multipart/form-data; boundary=fnord']
def "Execute revisions request"() {
setup:
String assetName = "testAsset1.jpg" as String
def assetProps = SetupTeardownUtils.getTestAssetProperties(assetName)
// upload it five times
for (i in 1..5) {
def result = sendRequest(assetProps.endPoint,'PUT',['Content-Type': 'multipart/form-data; boundary=fnord'], assetProps.bodyInBytes)
println "setup is uploading 5 test assets. Endpoint:[${assetProps.endPoint}] status:[${result.status}]"
}
when:
sendRequest('/api/repo/revisions/test/static/asset/upload/testAsset1.jpg', 'GET', ['Content-Type': V1_JSON])
then:
response.status == 200
response.contentAsString == '{"truncated":"false","status":{"success":"true"}}'
response.getHeader('Content-Type').equals(V1_JSON)
cleanup:
println "deleting the 5 test assets"
}
from grails-jaxrs.
From @marciomalewschik on August 11, 2015 2:28
Hello slackfarmer,
Could you please help me sharing how you did your resource to accept a MultipartFile.
I'm using this plugin in this verison:
compile ":jaxrs:0.11"
But until now I couldn't send a file to my resource.
In advance I thank you.
from grails-jaxrs.
From @prabhatsubedi on December 9, 2015 5:51
hello @marciomalewschik I am too facing same problem. Did you find solution ?
from grails-jaxrs.
Related Issues (20)
- How to output the POST request content? HOT 3
- Exception sending context initialized event to listener instance of class org.grails.jaxrs.web.JaxrsListener HOT 2
- Better jaxrs implementation choice support HOT 1
- HTTP Session while Request HOT 1
- Couldn't find grammar element for class HOT 17
- Is it possible to use jackson 2.X with Jersey, and so use @JsonView HOT 1
- jaxrs 0.11 grails 2.4.4 dependencies HOT 5
- Add support for Grails 3.x HOT 4
- Renderer makes date property null before db operation HOT 1
- How to get actual uri (i.e) api/v1/login/1234 instead of /grails/jaxrs.dispatch HOT 1
- grails war fails with ClassNotFoundException using jersey HOT 7
- Tomcat 8 fails to start application with jaxrs-core HOT 7
- ERROR org.springframework.boot.SpringApplication - Application startup failed HOT 2
- URL Mapping ??
- Base resources cause errors in Grails 3.2.4
- Sending file via Multipart form data
- No support Grails 3.3 HOT 10
- Jersey being intialized twice
- Failed to introspect class: class org.grails.plugins.jaxrs.Application in Grails 4.x HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grails-jaxrs.