How to Store a file uploaded in a Document Field in a Collection

Hello, I am working in a web site allowing the site members to upload document files for further management (validation, approvals, corrections…etc).
I have set a Collection with several fields. One of these is a Document Field Type and other is a URL field Type.

when I use the following code, I can upload the file an store it in the “Visitor´s uploaded Files” in the multimedia area, but when I tried to store the file in the Document Field in the collection data, I have the error/warning showed in the first image shared above.

this is my code:

Can you please share your code as text instead of a screenshot?

You can format it by encasing it as such:

```
let code = “here”;
function myCode() => {return true};
```

which will then format like:

let code = "here";
function myCode() => {return true};

Hi, thank by your answer

export function InsertCollectionButton_click(event) {  
        if ($w('#uploadButton1').value.length > 0) { // Site visitor chose a file
        console.log("InsertCollectionButton-----------------------------Uploading the following files:");
        $w('#text49').text = "Se está subiendo el siguiente archivo " + $w('#uploadButton1').value[0].name;
        $w("#uploadButton1").uploadFiles()
            .then((uploadedFiles) => {
                uploadedFiles.forEach(uploadedFile => {

                    $w('#text49').text = "El archivo se subió correctamente \n Puedes verificarlo en este Link. \n ";
                    $w('#button18').show();
                    $w('#button18').expand();
                    $w('#button18').link = uploadedFile.fileUrl;
                    $w('#button18').target = "_blank";
                    console.log("InsertCollectionButton -------------------------------File url:" + $w('#button18').link);
                    console.log("InsertCollectionButton -------------------------------Upload successful.");
                    console.log("InsertCollectionButton -------------------------------Upload successful.\n" + uploadedFile.originalFileName);    
                    // Guarda el archivo en la colección - Store new item in the collection
                    wixData.insert('MiDossier', {
                            title: $w('#input1').value,
                            tipoDeDodumento: $w('#dropdown1').value,
                            propietarioDelArchivo: LoggedMemberEmail,
                            document: uploadedFile.fileUrl,
                            descripcinDelDocumento: $w('#uploadButton1').value[0].name,
                            urlDocumento: uploadedFile.fileUrl
                        })
                        .then(() => {
                            // Éxito - Success
                            console.log('InsertCollectionButton -------------------------------Documento PDF subido y datos guardados con éxito.....*' + $w('#button18').link + "*");
                            console.log('InsertCollectionButton -------------------------------el urlDocumento es:' + $w('#button18').link);
                            // Muestro el Texto de éxito de Upload - Show the Text with Success of file upload
                            $w('#text49').show();
                                       
                        })
                        .catch((err) => {
                            // Error al guardar
                            console.error('Error al guardar en la colección:', err);
                            $w('#text50').show();
                        });
                    // Guarda el archivo en la colección

                })
            })
            .catch((uploadError) => {
                console.log("File upload error: " + uploadError.errorCode + "*" + uploadError.uploadFiles + "*");
                console.log(uploadError.errorDescription);
            });
    } else { // Site visitor clicked button but didn't choose a file
        console.log("Please choose a file to upload.")
    }
}

Can you share an example of a fileUrl that is causing this issue? I’ve just tried to reproduce and am not seeing this error.

Hi, this is the screen shot of document load page

This are the console debugging messages

the url is:

$w('#button18').link = uploadedFile.fileUrl;

wix:document://v1/cdd6f3_92a1f8d0a8974e0f89fb149307dee748.pdf/rejillas%20riobamba%20451.pdf

this is additional info:

// Referencia de la API de Velo: https://www.wix.com/velo/reference/api-overview/introduction
import { currentMember } from 'wix-members-frontend';
import wixUsers from 'wix-users';
import wixData from 'wix-data';

let user = wixUsers.currentUser;
let LoggedMemberId;
let LoggedMemberFullName;
let LoggedMemberEmail;
let MiDossierDocumentCount;

function GetLoggedUser() {
    // Escribe tu código de Javascript aquí usando la API de marco de Velo 

   //$w('#uploadButton1').enable();
   // $w('#input1').enable();
    //$w('#dropdown1').value = ">>";

    // Obtener el usuario en sesión
    user = wixUsers.currentUser;

    // Mostrar los datos del usuario
    if (user.loggedIn) {

        currentMember.getMember().then((member) => {
                const id = member._id;
                const fullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`;

                // Obtengo los datos del Miembro Loggeado
                LoggedMemberFullName = fullName;
                LoggedMemberId = id;
                LoggedMemberEmail = member.loginEmail;

                console.log('GetLoggedUser---------------------Logged User: Member Full Name: ' + LoggedMemberFullName + ' Member Id: ' + LoggedMemberId + ' Member Email: ' + LoggedMemberEmail);

                // Cargo en los controles para el 
                $w('#input1').value = fullName
                $w('#text70').text = LoggedMemberEmail;

                // obtengo la cantidad de documentos que tiene el Miembro Loggeado en la Colección MiDossier
                wixData.query("MiDossier")
                 .eq("_owner", LoggedMemberId)
                //.limit(20) // El número de elementos adicionales que deseas cargar
                .count()
                .then((num) => {
                         MiDossierDocumentCount = num;
                         $w('#text74').text= MiDossierDocumentCount.toString(); //cantidad de documentos en la colección
                         $w('#text75').text=$w('#repeater4').data.length.toString(); // cantidad de documentos mostrados en el repetior
                })
                .catch((error) => {
                 let errorMsg = error.message;
                 let code = error.code;
                 console.log('GetLoggedUser------------------error al contar la cantidad de documentos en el dossier: '+error.message+" :"+error.code);
                 });


                return member;
            })
            .catch((error) => {
                console.error(error);
                $w('#input1').value = "error";
            });

       

    } else {
        console.log("GetLoggedUser--------------------------------------Usuario no conectado");
        $w('#input1').value = "Usuario no loggeado";
    }


}


For the document column, when you hover over this icon does a tooltip appear with more info about the error?
image

This is the warning message



“El valor no coincide con el tipo de campo URL” (the value doesn’t match with the field Type URL)

this is the transformation of URL by clicking “Convertir valor a url” (convert the value to url)
But, doing that, the url has no access and the browser shows :about:blank#blocked

by other hand I saw that the field “Documento” is loaded in the correct format
and I can open it form CMS table and from Webpage. However I am confuse about where is actually stored the file: Is it inside of database of collection, or in the multimedia folder “Cargas del visitante” (“load of vistors”) ?