Coder Social home page Coder Social logo

Comments (6)

1cg avatar 1cg commented on July 24, 2024

can you post the code you are using?

from htmx.

aanon4 avatar aanon4 commented on July 24, 2024

What's the best way to provide this to you? It's part of a fairly large project, but this is the specific file which initiates the upload:

https://github.com/kn6plv/aredn/blob/ucode-http/files/app/main/status/e/packages.ut

from htmx.

1cg avatar 1cg commented on July 24, 2024

OK, so you are including an element in a form w/ a file input? If you could boil it down to the HTML and the javascript, stripping out the accidental stuff, that would be great. I'll try it locally too.

from htmx.

aanon4 avatar aanon4 commented on July 24, 2024

I've tried to extract the pertinent part of the code below (this is obviously not a runnable sample). There's a input file tag and a button which, when pressed, triggers the htmx.ajax to upload the file. This works fine with 1.X. With 2.X the encoding is correct and the payload arrives on the server and is decoded as I'd expect; except the packagefile.ipk just appears to be an empty object rather than the file data.

    <div style="flex:0">
        <input type="file" accept=".ipk">
    </div>
...
    <div style="flex:0">
        <button id="fetch-and-update" hx-trigger="none" hx-encoding="multipart/form-data">Fetch and Install</button>
    </div>
...
    <script>
    (function(){
...
        htmx.on("#fetch-and-update", "click", e => {
...
            const upload = htmx.find("#package-update input[type=file]").files[0];
...
            if (upload) {
                htmx.ajax("POST", "{{request.env.REQUEST_URI}}", {
                    source: e.currentTarget,
                    values: {
                        packagename: htmx.find("#package-update input[type=file]").value.replace(/^.*\\/, ""),
                        "packagefile.ipk": upload
                    },
                    swap: "none"
                }).then(_ => htmx.find("#package-upload progress").setAttribute("value", "0"));
            }

from htmx.

aanon4 avatar aanon4 commented on July 24, 2024

Taking a quick look at the ajax differences between 1.X and 2.0, I see that you're using a method called formDataFromObject to process the values passed in, and this doesnt understand what a file object is (so just JSONs it). In the 1.0 code the method used was mergeObject which had a much more simplistic approach to its arguments.

from htmx.

LucaPanofsky avatar LucaPanofsky commented on July 24, 2024

I think that this is also related to this issue: #2616 for now the API works with formData instead of plain objects

from htmx.

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.