Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control the Order of File Uploads in FilePond #1026

Open
2 tasks done
mikayelkotanjyan opened this issue Dec 9, 2024 · 0 comments
Open
2 tasks done

Control the Order of File Uploads in FilePond #1026

mikayelkotanjyan opened this issue Dec 9, 2024 · 0 comments

Comments

@mikayelkotanjyan
Copy link

mikayelkotanjyan commented Dec 9, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Have you updated FilePond and its plugins?

  • I have updated FilePond and its plugins

Describe the bug

In my current implementation, files uploaded via FilePond are processed and sent to the server automatically and in a random order. This behavior is undesirable when files need to be uploaded sequentially, based on a specific order (e.g., alphabetical, numerical, or based on user-defined parameters).

This is my code:
`
let audiobookId = {{$audiobook->id}};

@if(isset($uploadedFiles))
    const uploadedFiles = @json($uploadedFiles);
@else
const uploadedFiles = [];
@endif

const pond = FilePond.create(
    document.getElementById('{{$name}}'),
    {
        itemInsertLocation: (a, b) => {
            if (!(a.name && b.name)) return 0;

            if (a.name < b.name) {
                return -1;
            } else if (a.name > b.name) {
                return 1;
            }

            return 0;
        },
        files: uploadedFiles
            .map(file => ({
            source: file.id,
            options: {
                type: 'local',
                file: {
                    name: file.name,
                    id: file.id,
                    size: file.size,
                    type: file.type
                },
                metadata: {
                    poster: file.url
                }
            }
        })),
        credits: false,
        onremovefile: (error, file) => {
            if (!error) {
                const mediaId = file.serverId;
                fetch('{{ route("audiobooks.deleteMedia", ":id") }}'.replace(':id', mediaId), {
                    method: 'POST',
                    headers: {
                        'X-CSRF-TOKEN': '{{ csrf_token() }}',
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({ id: mediaId }),
                })
                    .then(response => response.json())
                    .then(data => {
                        console.log('File removed successfully:', data);
                    })
                    .catch(error => {
                        console.error('Error removing file:', error);
                    });
            }
        },
        onprocessfilerevert: (file) => {
            const mediaId = file.serverId;
            fetch('{{ route("audiobooks.deleteMedia", ":id") }}'.replace(':id', mediaId), {
                method: 'POST',
                headers: {
                    'X-CSRF-TOKEN': '{{ csrf_token() }}',
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ id: mediaId }),
            })
                .then(response => response.json())
                .then(data => {
                    console.log('File removed successfully:', data);
                })
                .catch(error => {
                    console.error('Error removing file:', error);
                });
        },
        server: {
            process: {
                url: '{{ route("audiobooks.uploadMedia", ":id") }}'.replace(':id', audiobookId),
                method: 'POST',
                headers: {
                    'X-CSRF-TOKEN': '{{ csrf_token() }}'
                }
            }
        }
    }
);`

Reproduction

No Reproduction

Environment

- Device: Any
- OS: Any
- Browser: Any
@mikayelkotanjyan mikayelkotanjyan changed the title [Bug] Control the Order of File Uploads in FilePond Control the Order of File Uploads in FilePond Dec 9, 2024
@rikschennink rikschennink removed the bug label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants