Comments (6)
can you post the code you are using?
from htmx.
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.
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.
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.
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.
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)
- Support a HTMX attribute to trigger webauthn HOT 1
- Intermittent issue in Safari: Refused to execute htmx script due to "X-Content-Type-Options: nosniff" HOT 3
- htmx 2.0.0 breaks <template> elements inside Web Components HOT 5
- htmx should preserve form element order when encoding form data for submitting via GET or POST
- HX-Location feature: push url options (example of working code, tiny change) HOT 3
- poll trigger for table content - how to keep/disable scroll on update HOT 1
- v2.0.0 hx-swap="delete" + hx-retarget="body" triggers uncaught exception HOT 1
- Extension Performance Improvments
- hx-swap="delete" should be allowed to work even with no request at all HOT 1
- Fetch hx-vals programatically HOT 2
- sha384sum is giving me the wrong answer for 2.0.1/dist/htmx.min.js HOT 1
- Does new extension released with core? HOT 2
- feature request: out-of-order rendering support
- `htmx:beforeRequest` and `htmx:beforeSend` event does not send on load trigger HOT 1
- `'htmx.d.ts' is not a module` HOT 5
- hx-trigger from:html with data-bs-theme HOT 1
- hx-swap-oob not working as expected HOT 2
- triggerEvent relies on a non-null target existing; therefore beforeSwap won't fire if target is null (possible when hx-retarget is used)
- Add the `pushUrl` option for `htmx.ajax()` calls
- UX is broken for streaming HTML HOT 2
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 htmx.