Wix makes it so EASY to upload to a collection without code, and it allows you to use code to upload to Media Manager…
But how on earth do we just grab the file data so I can send it to a backend function to send a POST request to a 3rd party API?
I have already successfully communicated with the 3rd party api with GET requests, but I can’t even begin to test this because I have no clue how to just grab the file contents. If this was plain JavaScript I could do this:
let data = document.getElementById("file").files[0];
But Wix does not allow access to the DOM. If I call the upload elements “.value” then all I get is an array with the file name and file size.
How do I just grab the data?
After that I assume I need something like this to send it on to the 3rd party API:
var FormData = require('form-data');var fs = require('fs');var form = new FormData();form.append('my_field', 'my value');form.append('my_buffer', new Buffer(10));form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
Looking for whatever help I can get, and I can pay for consultant time too. I saw a post in this Forum where yisrael said that to access DOM I could use the HTML widget and pass messages back and forth. I have used that approach before, but in this case I’m really hoping to skip the iframe and that there is something obvious I missed.
I can’t imagine why Wix would want to hide the file from us!
Velo-Ninja, thank you so much for your time. I did see that but discarded it because it relies on the media manager… If I have to resort to using the media manager, I guess I can - but there is zero need to store any of this in Wix. I am trying to take an applicants info and resume and send it to a recruiting platform through FETCH post requests. Is there anyway to just grab the file data so I can handle it with javascript? And I am not opposed to using a html-component I guess and use my method above - I just thought there had to be a way to do something as simple as accessing what is in an upload button.
The current working implementation is to just have an iframe in the Wix site and ignore Velo altogether. But I wanted to try and integrate more with Wix, so I was hoping this feature was possible. Maybe html-component is the way to go, I will look into that.
Any further thoughts on this? I have a similar need. I want my users to upload files which I can then relay to Google Cloud Storage where I have micro-services waiting to take over. I’ll go the iframe route if i have to, but I’m looking for an easy life. Is there really no way to be able to create a buffer / ReadStream from a file that’s been uploaded via an UploadButton? Seems like a pretty glaring omission.