Uploading From a Website
September 16, 2020The file is a long array of bytes. The file also has a name. But the name of a file is not inside the file. It is from the file system. When uploading from a web browser, it is sent in an HTTP request. That is a post. It can be from a form submit post or ajax post. The content type has to he multipart something, even when you are doing ajax. Usually all ajax are json. But here it is not json. We can have multiple files in a form. We can have files plus other form data in the body. The form post is an old style, still present. The browser loads it into the form if we can put an input element with type form inside a form element. There is a default button and then after choosing file, the file name is changed. We can change the style. It is a DOM with some state. The selected file information can be read by javascript in the browser. Form have submit. Before ajax this go to another url with post request. Now we can make submit call a listener function that get access to the form data. Anyway we have to send a multipart form HTTP. The web server frameworks, when they get the request they store it in the server’s local file system with a filenamw (is it new one chosen by the server or is the filename included in the request). And the request object receiced by controller, has the form data as well as the file descriptor. The server can do anything with the file. It can process it and return it and delete the original. Or it can store in an S3 bucket. S3 bucket gets it by a http request. But S3 can give an api to abstract away the details.