How to get the files uploaded in InMemoryUploadedFile django

不想你离开。 提交于 2021-01-27 05:39:17

问题


I am developing an application in django 2.1 in which I must upload an undetermined number of audios through a modal and then pass the information to the view from which the modal is launched. However, these audios should not be stored in the database until the main view form is filled out. Then I thought about these solutions:

First I thought about saving it as a session attribute but the contents of a FileField is not JSON serializable which did not work.

Second I thought about the LocalStorage property but if the files exceed the size I will have problems.

Third I thought about getting the file path and then create the audio but as I was reading is a bad practice and can only be obtained if the file is created on the disk, that is, if it is in TemporaryUploadedFile but my files should weigh less than one 1MB

For which I have the option that all files that are loaded with a size smaller than 2.5MB are stored in InMemoryUploadedFile but I do not know how to obtain them. Does anyone know how this is done? or how else can I save a list of temporary audios?


回答1:


InMemoryUploadedFile is a wrapper around a file object. You can access the file object using the file attribute.

file_in_memory # <InMemoryUploadedFile: xxx (xxx/xxx)>
file_object = file_in_memory.file


来源:https://stackoverflow.com/questions/55191466/how-to-get-the-files-uploaded-in-inmemoryuploadedfile-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!