Upload in folder's context option

Hello, you need the ability to upload files to the server with a standard uploader to the selected folder, while the upload button should be in the context menu of the folder, like this:

I tried to create an application that moves the downloaded file from the open directory to the selected folder, and then deletes the UI element of the downloaded file. But this method works extremely unstable:

    name: 'upload',
    displayName: t('files', 'Outload'),
    mime: 'dir',
    permissions: OC.PERMISSION_UPDATE,
    icon: OC.imagePath('core', 'actions/upload'),
    actionHandler: async function (fileName, context) {
        const targetDir = OC.joinPaths(context.dir, fileName);
        try {
            const data = await new Promise((resolve, reject) => {
                $('#file_upload_start').on('fileuploaddone', function (e, data) {
                $('#file_upload_start').on('fileuploadfail', function (e, data) {

                // Start the file upload process

            const uploadedFileName = data.files[0].name;
            const currentDir = OCA.Files.App.fileList.getCurrentDirectory();
            const sourcePath = OC.joinPaths(currentDir, uploadedFileName).split('/').map(encodeURIComponent).join('/');
            const targetPath = OC.joinPaths(targetDir, uploadedFileName).split('/').map(encodeURIComponent).join('/');
            const headers = { 'Destination': OC.linkToRemoteBase('dav/files/' + OC.getCurrentUser().uid + '/' + targetPath) };
            await new Promise((resolve, reject) => {
                    url: OC.linkToRemoteBase('dav/files/' + OC.getCurrentUser().uid + '/' + sourcePath),
                    type: 'MOVE',
                    headers: headers,
                }).done(function() {
                    console.log("File successfully moved");
                    // Save folder name to local storage
                    localStorage.setItem('movedToFolder', fileName);
                }).fail(function(jqXHR, textStatus, errorThrown) {
                    console.error("Failed to move file: " + textStatus + ", " + errorThrown);
                    reject(new Error("Failed to move file: " + textStatus + ", " + errorThrown));
            // Hide the file from the interface
            const movedToFolder = localStorage.getItem('movedToFolder');
            if (movedToFolder) {
                const $fileRow = $('tr[data-file="' + movedToFolder + '"]');
                $fileRow.css('height', '0');
                $fileRow.css('padding', '0');
                $fileRow.css('border', '0');
                $fileRow.css('opacity', '0');
                // Clear the folder name from local storage
        } catch (error) {
            console.error("An error occurred: ", error);

Unfortunately I have not fully understood your problem and can not help you. But you may be able to avoid the detour of downloading to the client by using the Transfer app. Unfortunately, this app, which is actually so important for a cloud, is quite unreliable and also currently not officially available for Nextcloud 27. Maybe you can ask a KI like https://chat.chatgptdemo.net to optimize your code.