Closed simonmoser-bluesource closed 4 months ago
Unfortunately, Retrofit does not support single MultipartFile https://github.com/trevorwang/retrofit.dart/issues/529
@StarProxima oh thanks for your answer! I used it with an array, which works. but was not aware that this is not possible with a single file with retrofit. 🙏
In the current generated code the
dart:io File
type is used. This is also used in the retrofit documentation.I'm no expert in dart but a File is always a real File in the file system: https://api.dart.dev/stable/3.3.0/dart-io/File-class.html
When i.e. I want to upload a file that is only available as byte array (i.e. an in memory image) to a server. I would have to save the byte array in a temp file and upload it.
A far simpler approach is to use
dio:Multipartfile
https://pub.dev/documentation/dio/latest/dio/MultipartFile-class.htmlA Multipartfile can also be loaded from a path. With this a File can easily converted to Multipartfile.
I manually changed the generated code to use
MultipartFile
instead ofFile
, but this would maybe a welcome change by others, since it makes it far easier to handle file uploads.The generated Code with MultipartFile:
Example Yaml: