how to send to backend file from dropzone only after choosed languages <!-- Create the…
- User
how to send to backend file from dropzone only after choosed languages
- Assistant
To send the file only after the target languages have been chosen, you can add a check in the "init" function of the Dropzone initialization script. Here is an example:
In this example, the "processing" event is used to check if the target languages have been chosen before the file is uploaded to the backend. If no target languages have been chosen, the file upload is cancelled and an alert is displayed to the user. If target languages have been chosen, the file upload continues normally.
- User
- Assistant
The issue could be that the data from the form is not being sent correctly to the backend. Double check that the name attribute of the input element for the target languages matches the parameter name in the backend function:
code<select id="target_lang_list" name="target_lang_list" ...>code@router.post("/multi-local-from-file") async def multi_local_from_file( data: UploadFile, target_lang_list: list[str] = Form(...), source_lang: str = Form(...) ) -> StreamingResponse: ...Also, make sure that the data sent in the request matches the expected data type in the backend. For example, the target_lang_list parameter is expected to be a list of strings, so make sure that it is being sent as such from the frontend.
- User
what type return this Choose your target languages {% for key, value in languages.items() %} {{ value }} {% endfor %} and could you show me an example what return this if it will be in form
- Assistant
The code you posted is HTML code, which is used to create a dropdown list for selecting multiple target languages.
When this form is submitted, it should send a list of selected language codes (e.g.
["es", "fr", "de"]) to the backend along with the uploaded file.In your backend function, the parameter
target_lang_listis expecting a list of strings. You can retrieve the data from the form in this format by using the name attribute of theselectelement in the form:code<select id="target_lang_list" name="target_lang_list" ...>In your Python code, you can retrieve this list from the frontend by using the
Formrequest model in FastAPI:codefrom fastapi import FastAPI, Form app = FastAPI() @app.post("/localization/multi-local-from-file") async def multi_local_from_file( data: UploadFile, target_lang_list: list[str] = Form(...), source_lang: str = Form(...) ) -> StreamingResponse: ... - User
how to send file from dropzone only after click on send button
- Assistant
- User
- Assistant
In your frontend code, you need to make sure that you're sending the form data in the correct format that the backend expects. For the
multi_local_from_fileendpoint, you need to send an uploaded file and a list of target language codes.You can retrieve the selected target languages with the following code:
codevar targetLangs = $("#target_lang_list").val();Then, you can prepare a
FormDataobject with the uploaded file and the target language codes, as shown below:code