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

Extend <Field.Upload /> with onFileDownload handler #4355

Closed
torryt opened this issue Dec 3, 2024 · 4 comments
Closed

Extend <Field.Upload /> with onFileDownload handler #4355

torryt opened this issue Dec 3, 2024 · 4 comments
Assignees

Comments

@torryt
Copy link

torryt commented Dec 3, 2024

🚀 Feature Proposal

Extend the <Field.Upload /> with a onFileDownload handler so that the full file can be downloaded on demand instead of pre-loaded in the form data.

Motivation

The <Field.Upload /> component expects input as an array containing the full File object. This means that when we preload a large form with several steps, and possibly several <Field.Upload /> components, we also have to load all the files already uploaded in the form and preload them into the form state, which can significantly delay the first page load.

Example

async function onFileDownload(fileId: string): Promise<Blob> {
  const response = await getFileFromServer(fileId);

  return await response.blob();
}

....

<Field.Upload
  onFileDownload={onFileDownload}
/>

onFileDownload expects an async function that returns a file blob. When the function is provided, it overrides the default behavior of the file link and downloads from server instead of downloading the File object in the form state.

Pitch

Reduces initial load time of forms with large files or many files and reduce unnecessary loading of documents that will probably not be downloaded.

@torryt torryt changed the title <File.Upload /> Extend <Field.Upload /> with onFileDownload handler Dec 3, 2024
@langz
Copy link
Contributor

langz commented Dec 5, 2024

Thanks for the detailed feature request, @torryt 🚀

I like the idea of a onFileDownload event or so, to download a given file from the server with a api request, and can definitely see the need for this.

I'll have to look more into how this works as of today.

I just took a quick search in the codebase, and as of today the code in Eufemia use multiple "file" properties, like name, size, lastModified, id, type, etc. Not sure what would happen if we don't provide these before the user clicks the link.

@langz
Copy link
Contributor

langz commented Dec 10, 2024

I think this feature request is solved with the following PRs which is included in v10.60.0 of Eufemia:

Please report back, and reopen the feature request if you find anything missing @torryt 🙇

@langz langz closed this as completed Dec 10, 2024
@torryt
Copy link
Author

torryt commented Dec 10, 2024

This works just as expected @langz . Thank you very much! 💯 🙏

@langz
Copy link
Contributor

langz commented Dec 10, 2024

This works just as expected @langz . Thank you very much! 💯 🙏

Great, thanks🤗
I have a small improvement/fix for when chaining multiple of these asynchronous upload events.

#4378

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants