How do I store a document in a collection?

So I’m using code to inject all inputs into a collection, and I have an Upload button that allows users to upload documents. However, in the inject, I entered upload: $w( ‘#upload’ ).value, which rather than storing the document itself in the collection, it just stores the name. How do I store the document itself in the collection? I saw startUpload( ) on the API, but my issue is that i need to be able to inject this outside the .then function because I have a lot of other stuff to inject to the collection.

Here is my code:
import wixData from ‘wix-data’ ;
import wixUsers from ‘wix-users’ ;
import wixWindow from ‘wix-window’ ;
import { doRegistration } from ‘backend/register’ ;
let user = wixUsers.currentUser;
let isUserLoggedIn = user.loggedIn;
$w.onReady(( function () {
if (isUserLoggedIn) {
$w( “#password” ).collapse();
$w( “#title” ).text = “Sign NDA” ;
user.getEmail()
.then((email) => {
$w( “#email” ).value = email;
});
}
}));

function validateRequiredFields(fieldKeys) {
let validationPassed = true ;
fieldKeys.forEach(fieldKey => {
let field = $w( ‘#’ + fieldKey);
if (field.validity.valueMissing) {
field.updateValidityIndication();
validationPassed = false ;
}
});
return validationPassed;
}

function clearFields(fieldKeys) {
fieldKeys.forEach(fieldKey => {
let field = $w( ‘#’ + fieldKey);
if (field.type === ‘$w.SignatureInput’ ) {
field.clear();
} else {
field.value = null ;
}
if (field.validity.valueMissing) {
field.resetValidityIndication();
}
});
}
export function signupButton_click(event) {
let termsIsChecked = $w( “#acceptTerms” ).checked;
let OpportinitiesIsChecked = $w( “#futureOpportunities” ).checked;
if ($w( “#futureOpportunities” ).checked) {
$w( “#futureOpportunities” ).value = “Yes” ;
} else {
$w( “#futureOpportunities” ).value = “No” ;
}
const item = {
firstName: $w( ‘#firstName’ ).value,
lastName: $w( ‘#lastName’ ).value,
email: $w( ‘#email’ ).value,
company: $w( ‘#company’ ).value,
position: $w( ‘#position’ ).value,
date: $w( ‘#date’ ).value,
upload: $w( ‘#upload’ ).value,
url: $w( ‘#url’ ).value,
phone: $w( ‘#phone’ ).value,
acceptTerms: $w( ‘#acceptTerms’ ).value,
futureOpportunities: $w( ‘#futureOpportunities’ ).value,
signature: $w( ‘#signature’ ).value
}
const keys = Object.keys(item);
if (validateRequiredFields(keys)) {
wixData.insert( ‘nda’ , item)
.then((results) => {
$w( ‘#successMessage’ ).show();
$w( ‘#validationMessage’ ).hide();
clearFields(keys);
})
. catch ((error) => {
console.log(error);
});
} else {
$w( ‘#validationMessage’ ).show();
}
if (isUserLoggedIn) {} else {
let firstName = $w( “#firstName” ).value
let lastName = $w( “#lastName” ).value
let company = $w( “#company” ).value
let email = $w( “#email” ).value
let password = $w( “#password” ).value
let position = $w( “#position” ).value
let phone = $w( “#phone” ).value;
doRegistration(email, password, firstName, lastName, company, position, phone)
.then((result) => {
let userId = result.user.id
let userInput = {
“firstName” : firstName,
“lastName” : lastName,
“company” : company,
“email” : email,
“position” : position,
“phone” : phone,
“_id” : userId
}
wixWindow.openLightbox( “Confirm your email” )
});
}
}
export function signature_change(event) {
$w( ‘#validationMessage’ ).hide();
$w( ‘#successMessage’ ).hide()
}

You cannot store files in the collection (neither an image nor a document).
You can upload a file to the servers and store its URL in the collection.
See here how to upload a file and get its URL:
https://www.wix.com/corvid/reference/$w/uploadbutton/startupload

I want to store files that my members upload and allow them to download later. However, they have personal data in them so I need to make sure it is secure and cannot be accessed by anyone else. I know how I can control access on my site, by only allowing members to be able to download their own files, but if the file itself is on a Wix server accessible by a URL, doesn’t this mean that someone could in theory get access to the document if they stumbled across the correct URL?

@cherierevells You can try and see if the File Share app let’s you set read permissions per user or not (I don’t know).
If it does not, you’ll have to use a third party for storing the file.

https://support.wix.com/en/article/about-the-file-share-app

https://support.wix.com/en/article/managing-permissions-in-the-file-share-app