flutter - Exception: toJson() method have to add to MultipartFile - Stack Overflow

While generating build this exception is thrown and unable to comple buildin fluter file using Multipar

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.

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.

Share Improve this question edited Nov 20, 2024 at 7:21 VLAZ 29.1k9 gold badges63 silver badges84 bronze badges asked Nov 19, 2024 at 23:07 63 - Vikas Kumar 4rd Sem.63 - Vikas Kumar 4rd Sem. 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
//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
    );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742392901a4435367.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信