Code Monkey home page Code Monkey logo

Comments (5)

bjorns avatar bjorns commented on June 5, 2024

Well, technically no other expectation has been set than strings but yes, I agree it would be nice to be able to write other types.

Do you have a link to how this works if I use curl?

from aem-cmd.

 avatar commented on June 5, 2024

@bjorns: In fact I realize now this is not a bug, but rather a feature request, because users can set the type via TypeHint's.

The curl syntax would be:

     curl -vv -u admin:admin -X POST --data 'aemFlag=true&aemFlag@TypeHint=Boolean&aemArr=[1,2,3,4,5]&aemArr@TypeHint=String[] http://localhost:4502/etc/tags/geometrixx-outdoors' 

or the same thing but in a more readable form:

    curl -vv -u admin:admin  \
        -F aemFlag=true \
        -F aemFlag@TypeHint="Boolean" \
        -F aemArr="[1,2,3,4]" \
        -F "aemArr@TypeHint=String[]" \
        http://localhost:4502/etc/tags/geometrixx-outdoors \

Adding support for it in the tool would mean interpreting value prefixes like {Boolean}true and converting them to extra TypeHint parameters, as documented at https://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#typehint

For booleans that are set to false that would also involve adding the @Delete:true type hint, since CQ deletes false properties rather than setting them to {Boolean}false.

from aem-cmd.

bjorns avatar bjorns commented on June 5, 2024

Ok, I think I'm going to put some basic type recognition and add a --typeHint flag just in case.

from aem-cmd.

bjorns avatar bjorns commented on June 5, 2024

Implemented integer and boolean support in 983666d

Unfortunately requests doesn't support having multiple form fields with the same name which seems to be what is required to set array data so that will remain known issue for the forseable future.q

from aem-cmd.

 avatar commented on June 5, 2024

@bjorns: Just for reference: in fact, requests can send multiple form fields with the same name. This is accomplished by sending a multipart/form-data POST request rather than a application/x-www-form-urlencoded POST where the files parameter is a tuple so that multiple fields with the same name can be sent.

AEM itself uses multipart form encoding for most POST operations rather than www-form-urlencoded.

The requests equivalent would be requests.post('http://httpbin.org/post', files=dict(foo='bar')) which I have found to be tricky to use since it requires ugly and un-intuitive syntax when you don't want to include files, given that files is mainly meant for file uploading and the API for using it for multipart form posting without files is imo faulty.

A nicer alternative to using files is the requests_toolbelt which is an extension for requests. I included an example at http://stackoverflow.com/a/35974071 which basically looks like:

    import requests
    from requests_toolbelt.multipart.encoder import MultipartEncoder

    multipart_data = MultipartEncoder(
        fields=(
                ('action', 'store'), 
                ('path', '/path1'),
                ('path', '/path2'),
                ('path', '/path3'),
               )
        )

    response = requests.post('http://httpbin.org/post', data=multipart_data, headers={'Content-Type': multipart_data.content_type})

from aem-cmd.

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.