Exception: toJson() method have to add to MultipartFile

While generating build this exception is thrown and unable to comple buildin fluter file using MultipartFile in Retrofit Multipart

@POST("upload")
@MultiPart()
Future<UploadFileResponse> uploadWallpaperImage(
    @Part(name: "files") MultipartFile wallpaperImage,
    @Query("populate") String populate
    );

here is the logs


Deprecated. Use `dart run` instead.
Building package executable... (1.0s)
Built build_runner:build_runner.
[INFO] Generating build script completed, took 900ms
[INFO] Reading cached asset graph completed, took 391ms
[INFO] Checking for updates since last build completed, took 1.4s
[SEVERE] retrofit_generator on lib/data/network/api/wallpaper_api.dart:

Exception: toJson() method have to add to MultipartFile
[WARNING] No actions completed for 17.0s, waiting on:
  - json_serializable on lib/data/data_sources/wallpaper_remote_data_source.dart
  - json_serializable on lib/app/app.dart
  - json_serializable on lib/presentation/pages/home/home.dart
  - json_serializable on lib/presentation/route/page_route.dart
  - json_serializable on lib/presentation/pages/profile/profile.dart
  .. and 9 more

[INFO] Running build completed, took 32.1s
[INFO] Caching finalized dependency graph completed, took 558ms
[SEVERE] Failed after 32.7s

I am working on flutter web application project cannot know how to handle correctly and unsing file_picker unable to get access of file path, so i am using MultipartFile.

Upvotes: 1

Views: 236

Answers (1)

ayman omara
ayman omara

Reputation: 344

//note that the File is coming from dart:io 
@POST("upload")
@MultiPart()
Future<UploadFileResponse> uploadWallpaperImage(
//replace MultipartFile with File
    @Part(name: "files") File wallpaperImage,
    @Query("populate") String populate
    );

Upvotes: 0

Related Questions