How to do multipart form request using sttp library. Below is the sample curl request.
curl -X POST \
http://localhost:2004/v2/api/artifacts \
-H 'cache-control: no-cache' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F file=@/Users/username/filename
Below is the scala code.
val request = sttp
.multipartBody(multipart("file", new FileInputStream(filePath)))
.post(uri"$mistApiUrl/v2/api/artifacts")
val response = request.send()
The field file is not being sent properly.
Problem solved. Solution details here.
fileName needs to be called upon using InputStream in multipart form-data.
val request = sttp
.multipartBody(multipart("file", new FileInputStream(filePath)).fileName(fileName))
.post(uri"$mistApiUrl/v2/api/artifacts")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With