Error in function definition: files.searchFiles

Question:

Error in function definition: files.searchFiles (wix.media.v2)

I am using optional parameter: rootFolder(string) with value: “VISITOR_UPLOADS_ROOT”
because I want to know the ID of all the files that the user has uploaded. To work, it works, but in the editor I get an error message in the parameters. Where am I doing wrong? Thank you.

It’s hard to say what your exact error is without more context, but here’s what the error is saying:

You’re using an object “options” with the properties rootFolder (type String) and nameFile (any type). This means that the parameter for your function myElevatedSearchFile(parameter), doesn’t align with the “options” object you fed into it.

Try writing some console.logs to figure out the type of SearchFileOptions, and make sure your “options” const matches up to that.

Hi Emmy,
I’m having trouble understanding the problem.
We can tell ourselves to look at the parameters that are not of the recognized type, but, here it is a question of solving the problem as per the example in the documentation.

I’m not making this up, but it seems the only accepted parameter is: search. For all others it displays the warning.

Then I need to take only the files uploaded by the user: “VISITOR_UPLOADS_ROOT” both of type ‘IMAGE’ and ‘DOCUMENT’.

Something is missing?
I don’t know.

Greetings

If you think it is appropriate, I will attach the function.

/*********************************************************************************************************************************

  • Function that obtains information on a file uploaded by the user in Media Manager in the folder: “VISITOR_UPLOADS_ROOT”

  • Parameters: nameFile=Name of the file to search; urlFile = OPTIONAL => url of the uploaded file

  • If the file is found, the file ID returns.

  • For NOT FOUND it returns an empty string; for ERROR displays the error
    */
    export async function GetIDFile(nameFile, urlFile = “”) {
    let resultIDFile = “”;
    let srootFolder = “VISITOR_UPLOADS_ROOT”;
    let mediaTypes = [“IMAGE”, “DOCUMENT”, “ARCHIVE”];
    let search = String(nameFile);
    try {
    const options = {
    mediaTypes: mediaTypes,
    rootFolder: srootFolder,
    search: search
    }
    const myElevatedSearchFile = wixAuth.elevate(files.searchFiles);
    const result = await myElevatedSearchFile(options);
    if (!ObjectIsEmpty(result)) {
    let arrayFiles = result.files;
    for (let index = 0; index < arrayFiles.length; index++) {
    const element = arrayFiles[index];
    if (ObjectIsEmpty(urlFile)) {
    if (element.displayName === nameFile) {
    resultIDFile = element._id;
    break;
    }
    } else {
    let staticurlFile = “”;
    if (urlFile.includes(“https://”))
    staticurlFile = urlFile;
    else
    staticurlFile = await TransformWixImageToStaticURL(urlFile);

                 if ((element.displayName === nameFile) && (element.url === staticurlFile)) {
                     resultIDFile = element._id;
                     break;
                 }
             }
         }
     }
    

    } catch (error) {
    console.error(error);
    }
    return resultIDFile;
    }