Anyone knows how to do that? There is an old thread from tjc that claims it’s impossible:
https://together.jolla.com/question/214496/how-to-send-a-file-using-xmlhttprequest/
but maybe it got read-only before an answer existed.
Thanks in advance
Forgive my ignorance, but what sort of handle do you have on the file?
It’s some nemo.picker or something like that, can you pass that to xhr?
So basically just a path/name then? If it survives being read into a string (AFAIK the only file reading thing in QML is XMLHttpRequest, also for local files), you could relay the contents. But for things like images, i can’t help but think you might be out of luck, as per the previous answer. (But do test…)
Since XMLHttpRequest is from standard JavaScript, which is very browser-centric, i think passing arbitrary local files, referred to just by name, is not really in the cards.
You could read it byte by byte in JS? But not sure how to pass that over? As multipart/form-data with custom boundary? In theory should be possible?
I’d assume that is exactly what lack of typed arrays trips up, but that is really a bit outside my knowledge.
However… that might be fake news, as they supposedly got included in Qt 5.5 What's New in Qt 5.5 | Qt 5.15
Yeeeah, I’ve no clue, I just tinker on my phone and was hoping there is a way to do a one-liner, this is way over my head, but if a simple JS function can read a file and pass it over QML, it seems like it would be all that’s needed (unless implemented in Qt 5.12, but 5.5 seems great)
I think it basically goes as follows (if at all): send request for local file, read that out as typed array, re-ship that in request to remote server.
I really hate this part:
This example uses plain text, but you can imagine the data being a binary file instead.
I can imagine a lot of things, but just wanted a QML example of sending binary data with some text data on top and if we look at the beginning of the thread it’s impossible?
edit: oh wait, you probably meant the next part: sending typed arrays as binary data, nvm
Could also be that whatever the example from Receiving binary data in older browsers returns can go straight into the next request too.
Can you point the relevant part? It’s about GET request and has no relation to making a POST with binary?
I’m thinking you want to do what their load_binary_resource()
on your local file, then try to feed that returned value to the POST request.
If that doesn’t do it, try to figure out if reshaping that to a typed array helps.
Oh wait is xhr the only way for JS to interact with files within QML?
¯\_(ツ)_/¯
You should be able to load a file with Canvas as binary and then reread it back with getImageData, maybe?
add a bit of c++/qt code maybe?
Yeah, with python/C++ it gets easy, but it’s always lazy now vs recompiling for aarch128 later (or being ded by that time, btw holy shit glad you’re still around man)
What happens if you just load an Image{}, can’t you read it’s values or like >> them out from .data? I’m really shit at QML
Also pure QML code can be easily reviewed? I assumed that would be valued in the regions of the world this would be applicable to
this is why CI/CD exists