Sopamo / laravel-filepond

Laravel backend module for filepond uploads
MIT License
202 stars 56 forks source link

Restore example? #51

Closed andreaselia closed 3 years ago

andreaselia commented 3 years ago

Hey, awesome package and very useful.

I'm working on adding "restore" functionality, but ran into an issue where filepond always displays "upload complete" for chunked files.

As you can see from the below code, I return the file and header as expected via the filepond documentation.

public function restore(Request $request, string $id)
{
    $disk = config('filepond.temporary_files_disk', 'local');
    $path = config('filepond.temporary_files_path', 'filepond').DIRECTORY_SEPARATOR.$id;

    $mime = Storage::disk($disk)->mimeType($path);
    $file = Storage::disk($disk)->get($path);

    return Response::make($file, 200, [
        'Content-Type' => $mime,
        'Content-Disposition' => 'inline; filename="'.$id.'"',
    ]);
}

Routes (overwritten):

// Filepond
Route::prefix('filepond')->group(function () {
    Route::patch('/', [FilepondController::class, 'chunk'])->name('filepond.chunk');
    Route::post('/process/{video}', [FilepondController::class, 'upload'])->name('filepond.upload');
    Route::delete('/process/{video}', [FilepondController::class, 'delete'])->name('filepond.delete');
    Route::get('/restore/{id}', [FilepondController::class, 'restore'])->name('filepond.restore');
});

Frontend JS:

FilePond.setOptions({
    chunkUploads: true,
    server: {
        url: '/filepond',
        process: '/process/{{ $video->id }}',
        revert: '/process/{{ $video->id }}',
        restore: '/restore/',
        headers: {
            'X-CSRF-TOKEN': '{{ csrf_token() }}',
        }
    },
});

const inputElement = document.querySelector('.filepond');
const pond = FilePond.create(inputElement, {
    files: [
        {
            source: '9K3Z9t0DSEU4tfFI', // example chunk id
            options: {
                type: 'limbo',
            },
        },
    ],
});

Visiting the page with filepond integrated then displays:

image

But I'd expect it to continue the upload which was interrupted.

Any suggestions would be greatly appreciated.

iamB0rgy commented 1 year ago

@andreaselia You closed it without fixing it coz you are fed up or you closed it because you fixed the issue and didn't want to share how you fixed it?

andreaselia commented 1 year ago

@iamB0rgy I don't fully remember, but if I am remembering correctly, it wasn't actually possible to do what I wanted to achieve here.

My apologies for not updating the issue when I closed it.

iamB0rgy commented 1 year ago

@iamB0rgy I don't fully remember, but if I am remembering correctly, it wasn't actually possible to do what I wanted to achieve here.

My apologies for not updating the issue when I closed it.

What did you use then? Please give me an idea. I'm stuck in here. Thanks

andreaselia commented 1 year ago

@iamB0rgy I don't fully remember, but if I am remembering correctly, it wasn't actually possible to do what I wanted to achieve here. My apologies for not updating the issue when I closed it.

What did you use then? Please give me an idea. I'm stuck in here. Thanks

I genuinely don't remember. I think we may have skipped the idea of "restoring" and instead allowed users to upload a file in its whole (and restart if it failed), and then ran a job to do what we needed to with the file afterwards, but again, I don't recall unfortunately and no longer work at the company where I was working with filepond on a project. Sorry about that.

iamB0rgy commented 1 year ago

No worries. I'm pretty sure the author will answer after a decade. 😁