Under SpringBoot, the uploaded information includes text and multiple pictures. How to wait for the picture to be uploaded, return the address for processing, and save it to the database together with the text?

I would like to describe in detail the problems I have encountered. For example, I am going to publish an article, and this article contains not only text, but also a few pictures. If you directly request the interface, the background receives the file, after a series of processing, and return the image to the address in the server, and save it to the database together with the text message, then the problem comes now.

File upload I wrote a tool class, called this tool class, and then used jsonArry to receive the returned server address, while the backend interface continued to save the data before waiting for jsonArray to get the returned information, so every time the jsonArray was empty. After a while, the console printed out the upload completion, the return address prompt, roughly online search, all said to use thread pool, but did not specify how to use it. There is a comparison of food, but I don"t know how to read the code source. If you have done similar processing, please help me

.
Feb.13,2022

two solutions:

  1. upload pictures separately.
    create a datasheet of pictures, and return id and picture access links for each picture uploaded. When the front end publishes the article, bring the picture id and other article content together, and then complete the storage operation in the background.
  2. submit as a whole.
    Click the submit button in the foreground, receive an array of pictures and other related fields at the same time in the background, and save the images one by one, and then complete the article data storage operation after successfully storing the article data

you're thinking too much. This is the content of front-end processing, and it is not something that needs to be considered in the background at all. The frontend calls the upload API first, and then submits the content to the database after the image has been uploaded.

Menu