Giter Site home page Giter Site logo

Multipart Form Data about grails-jaxrs HOT 3 OPEN

budjb avatar budjb commented on June 27, 2024
Multipart Form Data

from grails-jaxrs.

Comments (3)

budjb avatar budjb commented on June 27, 2024

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.

budjb avatar budjb commented on June 27, 2024

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.

budjb avatar budjb commented on June 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.