Example of POST request with Multipart file ! #1471
lilian-delouvy
started this conversation in
Show and tell
Replies: 1 comment
-
It did, thanks a lot man :) I can confirm this method works for a FastAPI application that uses UploadFile. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone !
Here is an example of a functionning request to send Multipart files with Bruno.
As an example, I used a really basic Spring boot application with a PostMapping route that receives a MultipartFile object and a String "sampleValue".
Here is the content of the controller, just for the sake of clarity:
Now, create a Bruno request of POST type with the required url (in my example, "http://localhost:8080/send-file") and set the header "Content-Type": "multipart/form-data" in the relevant tab.
In the "Body" tab, specify the type of file as Multipart. You can also define the parameters, but they will be set in the "Vars" tab, so this is more for documentation purposes.
In the "Vars" tab, specify the variables:
Note: if you're on Windows, you will have to tweak your absolute path a bit. By default, you will have something like "C:\something\somethingelse\yourfile.txt". You will have to either update this to "C:\something\somethingelse\yourfile.txt" or "C:/something/somethingelse/yourfile.txt".
Now, we will create our script:
We're almost ready ! But by default, Bruno is not allowed to access files on your computer, nor is it allowed to use NPM packages without your consent. We do need file system handling and the "form-data" package though. (Note: don't forget to install "form-data" on your computer for this script to work, with
npm i -g form-data
for instance).EXIT BRUNO as the following will corrupt your collection otherwise (at least, that's what happened to me on my first try).
Go to your "bruno.json" file that defines your collection (as a reminder, you can find the path where you stored it in the settings of you collection, in the "Info" tab). Update it to look like the following:
This allows Bruno to use "fs" and "form-data".
Save the file, and you can open Bruno again. Your request is ready !
I hope this helped you :)
Beta Was this translation helpful? Give feedback.
All reactions