Skip to content

file uploads #24

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

Closed
gwado opened this issue Jul 11, 2023 · 6 comments · Fixed by #139
Closed

file uploads #24

gwado opened this issue Jul 11, 2023 · 6 comments · Fixed by #139
Labels
enhancement New feature or request

Comments

@gwado
Copy link

gwado commented Jul 11, 2023

Hello,
Is it possible to integrate a "files" or "uploads" component that would make it possible to upload a file via the form?
Each file could be stored in a "uploads" folder (by default) and metadata in a table named "uploads" (by default) with the following fields (e.g.) : id, uuid-name, date-created.

@lovasoa lovasoa added the enhancement New feature or request label Jul 11, 2023
@lovasoa
Copy link
Collaborator

lovasoa commented Jul 11, 2023

Hi !
Yes, handling uploads is on the roadmap. But I'm not a huge fan of the uploads folder and the uploads table.

SQLPage is completely agnostic to your database or folder structure so far, and I'd like it to stay this way. You can use sqlpage with a read-only database, you can use it with a database on which you don't have the permission to create new tables, you can use it on a read-only filesystem, and that's something I'd like to keep.

The way I was thinking about this feature was adding sqlpage pseudo-functions :

  • sqlpage.uploaded_file('name')
  • sqlpage.base64() to be used with standard INSERT statements to make it easy to save files directly in the database and reuse them
  • and maybe a component to save data to disk (SELECT 'save_file' AS component, 'xxx' AS filename, sqlpage.uploaded_file('name') AS contents)

@gwado
Copy link
Author

gwado commented Jul 11, 2023

Why not use sqlpage/sqlpage.json to allow certain parameters, such as the upload folder, to be modified?
If I'm not mistaken: we can integrate a js script into a template to, for example, resize an image before uploading it. Yes ?

It's true that these reflections are very touchy, because the basic idea of simplicity is excellent, and every addition shouldn't call it into question with the risk of creating a bag of knots.

@lovasoa
Copy link
Collaborator

lovasoa commented Jul 16, 2023

Here is what I think needs to be done:

  • Add enctype=multipart/form-data to forms in the form component
  • Add a dependency to actix-multipart, with the tempfile optional dependency
  • Parse request bodies as multipart in extract_request_info in http.rs. Save files as tempfiles.
  • Add two new functions
    • sqlpage.uploaded_file_dataurl('name') which returns an uploaded file as a data url
    • sqlpage.uploaded_file_path('name', 'folder') which copies the file to the given folder with a secure random name and returns the path

Let me know what you think. If you are interested in implementing it yourself, let me know and I'll guide you through the code and review your pr. If you need that done by me, contact me on [contact at ophir dot dev] and we'll agree on a small dev contract.

@lovasoa lovasoa changed the title uploads file uploads Sep 19, 2023
@lovasoa lovasoa mentioned this issue Nov 23, 2023
@lovasoa
Copy link
Collaborator

lovasoa commented Nov 24, 2023

Hey ! It took a long time, but I just merged the big files update. It will be in the next version unless someone finds a big issue with it before the release. The easiest way to test it for now is by using the lovasoa/sqlpage:main image on docker.

I think the final result is both easy enough to use and flexible. Have look at the release notes !

@gwado
Copy link
Author

gwado commented Nov 27, 2023 via email

@lovasoa
Copy link
Collaborator

lovasoa commented Nov 27, 2023

If you want to contribute to the project, but don't know rust, a useful thing to do would be contributing to the examples and to the official site. Both get a continuous flow of visits, and I think there is still a lot of room for improvement to make them clearer and more pedagogical. A lot of formulations still use technical jargon without defining it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants