S
S
serikd2017-09-29 22:23:22
Database design
serikd, 2017-09-29 22:23:22

What are the approaches for uploading files to a post before the post is created?

Hello.
What are the approaches for uploading files to a post before the post is created?
For example - Click the button to add news, first upload pictures to it (AJAX), then write the text itself and only after that click the save news button.
What is the best way to load related files at all before the parent exists?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Stanislav Menshov, 2017-10-03
@SWEBB

It can be even simpler.. Use JS FileReader (this is a built-in JavaScript WEB API)
https://developer.mozilla.org/en/docs/Web/API/File...
You have a submit form, the trick is that the user can upload pictures and if he changes his mind to send a post, the pictures will not get to the server until there is a submission. But he can see them.
The process is very simple:
1. The user writes something (or doesn’t write)
2. Uploads an image to input=file, it is read in base64 via FileReader (FileReader can also validate their mime/types and size!)
3. Create a temporary img tag ( document.createElement('img').src = ) or input=hidden with the hash of the image... or both to show it the image instantly and then save it on submit...
4. When you click submit - save the form. Data to the database or somewhere ... and read the picture from the input stream
php.net/manual/en/wrappers.data.php (for PHP example)
5. Create a new empty file and write the stream to it
Total: the user can click on images at least 100 pieces and think that they have loaded, but they are saved only when the form is processed

D
Dimonchik, 2017-09-29
@dimonchik2013

https://blueimp.github.io/jQuery-File-Upload/
here it is in /tmp for a couple of hours
while there is no parent - no pictures either

P
Ptolemy_master, 2017-09-30
@Ptolemy_master

This is how we organize it.
The user writes a post. He wanted to insert a picture, please, clicks the button, a file selection window is displayed, the file is loaded --> continues to write a post, inserts a picture again (pictures can be inserted as you write), finished, saves. All pictures go to his personal folder. Later we will have an interface for accessing all uploaded files, but for now, that's it. Files are uploaded to the server via an API that returns the path to the file - this link is simply pasted into the post (even before it's saved).
One disadvantage with this approach is if the user suddenly changes his mind about writing a post, and the files have already been downloaded and are sitting in his folder. In this case, you can run a program on a schedule that will check whether this file is being used or not, and if not, then delete it (however, it is not known, maybe the user just uploaded pictures for a future post).

X
xmoonlight, 2017-09-30
@xmoonlight

Creating a post is like a transaction: in 3 steps.
1st stage: this is the creation of a "container" of the publication and filling it with all the necessary information (text, pictures, videos, code, etc.)
2nd stage: this is saving the current current version and adding the previous one to the archive of changes (versioning)
3 th stage: publication for all - release of the post.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question