Request for support on FormData
RaghuManickam opened this issue · 2 comments
RaghuManickam commented
Hi ,
I have been using this library quite a long time . I face a issue while uploading file so I use dio(formdata) to upload files to fix my current issue . is there any way to upload files in this library.
I have added my dio code snippet and I have added retrofit code also . Please correct me if i am wrongly implemented.
Dio Code:
FormData formData=FormData();
formData.add("image", new UploadFileInfo(image[0], "image.jpg",contentType: ContentType.parse("multipart/form-data")));
formData.add("json", postImageModelToJson(postImageModel));
print(formData.toString());
var response=await dio.post("http://xxxx",data: formData,options: Options(headers: {
HttpHeaders.authorizationHeader:"xxxxx"
}
print(response.request.data);
Retrofit Code:
@PostReq(path: "xxxx")
Future<StringResponse> savePodDetails(
@Header("Authorization") String token,
@AsMultipartField("file") MultipartFile image,
@AsMultipartField("orderId") MultipartStringFile orderId,
@AsMultipartField("documentTypeMasterId") MultipartStringFile documentId);
Future<String> onSavePod(File file, String documentId, String orderId) async {
List<int> bytes = await file.readAsBytes();
var image = MultiPartImage(file,
fileName: 'image.jpg', contentType: new MediaType.parse("image/jpeg"));
await mApiInterface
.savePodDetails(
await customSharedPrefs.getToken(),
MultipartFile(bytes,
contentType: new MediaType.parse("image/jpeg"),
filename: 'file'),
MultipartStringFile(orderId,
contentType: new MediaType.parse("text/plain"),
filename: "orderId"),
MultipartStringFile(documentId,
contentType: new MediaType.parse("text/plain"),
filename: "documentTypeMasterId"))
.then((str) {
return Future.value(str.body.toString());
}).catchError((error) {
return Future.value(error.toString());
});
}
jaumard commented
Looks ok to me, what jaguar version do you use ? what's the error ?
RaghuManickam commented
Sorry The issue was from my side . I used image/jpeg instead of multipart/form-data. That's why the image didn't upload !