undefinedfix
Sign in

How to upload files uniformly

mmeisner edited in Fri, 26 Aug 2022

At present, the business is more complicated and the internal system is maintained more. Each system needs an independent file upload related module (in addition to simple file upload, it also needs to consider file backup, user upload temporary file processing and other repetitive logic). At present, it only unifies some logic codes to deal with upload restrictions into the framework. I would like to ask if we want to unify them into one file What should I pay attention to in the service module of upload

3 Replies
wpqwi
commented on Sat, 27 Aug 2022

A unified file upload system needs to consider several points

  1. File storage form, whether to use distributed database, whether to back up two copies, three copies
  2. File size checking algorithm, file duplicate checking algorithm, file name, file content hash, whether different versions of the same file need to be stored, whether differential storage is needed
  3. Different business projects have independent upload address and image access address, how to distinguish
  4. Do you need to optimize the image file, such as image compression, clipping, automatic generation of thumbnails
  5. Support large file breakpoint continuation, support multi map upload
  6. Each specific business project can write its own upload processing algorithm and file access algorithm
qmuyq
commented on Sat, 27 Aug 2022

Create a new upload class, encapsulate the original upload method, upload path, storage path, validation rules, generation rules are all passed in when calling, you can refer to the processing flow in other frameworks

Lancet
commented on Sat, 27 Aug 2022

It is encapsulated as a function module, but the places that may have different characteristics and parameters are replaced by incoming parameters, such as upload address, backup address, etc. Secondly, if there are some modules with consistent small functions in the upload function, they will be packaged separately. In this way, if there are different business logic of each system, you only need to write it separately and put it in a certain position in this module.