chopper icon indicating copy to clipboard operation
chopper copied to clipboard

http.MultipartFile not found in auto generated chopper.dart

Open josephchenghmlet opened this issue 4 years ago • 7 comments

Hi, i've tried to add MultipartFile which is from package:http/http.dart as http but the auto generated chopper file return error.

Followed #55, #65

How do I send multiple Multipart files with same multipart key?

chopper: ^3.0.0 chopper_generator: ^3.0.0


// api_service.dart
...
import 'package:http/http.dart' as http;
...
@Post(path: "support/", headers: {"Authorization": ""})
  @multipart
  Future<Response> submitNewTicket({
    ...
    @PartFile('attachment') List<http.MultipartFile> attachments,
  });
...
// api_service.chopper.dart

Future<Response> submitNewTicket(
      {List<MultipartFile> attachments}) { // error red line at `MultipartFile`
    final $url = 'support/';
    final $headers = {'Authorization': ''};
    final $parts = <PartValue>[
      PartValueFile<List<MultipartFile>>('attachment', attachments) // error red line at `MultipartFile`
    ];
    final $request = Request('POST', $url, client.baseUrl,
        parts: $parts, multipart: true, headers: $headers);
    return client.send<dynamic, dynamic>($request);
  }

josephchenghmlet avatar Aug 17 '19 10:08 josephchenghmlet

@josephchenghmlet could you resolve your problem?

pishguy avatar Aug 29 '19 05:08 pishguy

Hi @MahdiPishguy, I've switched todio temporary for post multipartfile.

josephchenghmlet avatar Aug 29 '19 23:08 josephchenghmlet

Welcome back @lejard-h

josephchenghmlet avatar Sep 25 '19 22:09 josephchenghmlet

aliased import seems difficult to handle with source_gen, I can't find any resource to help me.

But you can change your import to import 'package:http/http.dart' show MultipartFile; or just import 'package:http/http.dart';

lejard-h avatar Sep 29 '19 12:09 lejard-h

Hi @lejard-h, thank you. Let me try and update you if there's outcome.

josephchenghmlet avatar Sep 30 '19 01:09 josephchenghmlet

It's the exact same thing with BuiltValue. From some reason, code generators, in general, are having difficulty with library aliases.

daniel-v avatar Oct 05 '19 10:10 daniel-v

I think I'm having this same issue. If I

import 'package:chopper/chopper.dart' as ch;

then my generated code does NOT contain the import prefix.

IanWorthington avatar Apr 13 '21 20:04 IanWorthington