Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9079
Something went wrong while setting issue due date.
Closed
Open
Issue created 4 years ago by Administrator@rootContributor
  • New related issue

  • Report abuse to administrator

  • New related issue

  • Report abuse to administrator

[DART-dio] Can't send body and binary data

Closed

[DART-dio] Can't send body and binary data

Created by: jaumard

I have the following definition:

"/api/v1/shops/{shop_id}/transactions/{id}/signature":
    patch:
      operationId: patch_shops_transaction_signature_partial
      description: ""
      requestBody:
        content:
          image/png:
            schema:
              type: string
              nullable: true
              format: binary
        description: signature image to upload
        required: true
      responses:
        "201":
          description: All good
      tags:
        - transactions

This is generated like this:

Future<Response<void>> patchShopsTransactionSignaturePartial(
    int id,
    int shopId,
    Uint8List body, { 
    CancelToken cancelToken,
    Map<String, dynamic> headers,
    Map<String, dynamic> extra,
    ValidateStatus validateStatus,
    ProgressCallback onSendProgress,
    ProgressCallback onReceiveProgress,
  }) async {
    final _request = RequestOptions(
      path: r'/api/v1/shops/{shop_id}/transactions/{id}/signature'.replaceAll('{' r'id' '}', id.toString()).replaceAll('{' r'shop_id' '}', shopId.toString()),
      method: 'PATCH',
      headers: <String, dynamic>{
        ...?headers,
      },
      extra: <String, dynamic>{
        'secure': <Map<String, String>>[
          {
            'type': 'apiKey',
            'name': 'Bearer',
            'keyName': 'Authorization',
            'where': 'header',
          },
        ],
        ...?extra,
      },
      validateStatus: validateStatus,
      contentType: [
        'image/png',
      ].first,
      cancelToken: cancelToken,
      onSendProgress: onSendProgress,
      onReceiveProgress: onReceiveProgress,
    );

    dynamic _bodyData;

    _bodyData = body;

    final _response = await _dio.request<dynamic>(
      _request.path,
      data: _bodyData,
      options: _request,
    );

    return _response;
  }

But this is not working, the correct way of sending the data is like this according to this issue of dio (https://github.com/flutterchina/dio/issues/1036):

Future<Response<void>> patchShopsTransactionSignaturePartial(
      int id,
      int shopId,
      Uint8List body, {
        CancelToken cancelToken,
        Map<String, dynamic> headers,
        Map<String, dynamic> extra,
        ValidateStatus validateStatus,
        ProgressCallback onSendProgress,
        ProgressCallback onReceiveProgress,
      }) async {
    final _request = RequestOptions(
      path: r'/api/v1/shops/{shop_id}/transactions/{id}/signature'.replaceAll('{' r'id' '}', id.toString()).replaceAll('{' r'shop_id' '}', shopId.toString()),
      method: 'PATCH',
      headers: <String, dynamic>{
        ...?headers,
        'Content-length': body.length,
      },
      extra: <String, dynamic>{
        'secure': <Map<String, String>>[
          {
            'type': 'apiKey',
            'name': 'Bearer',
            'keyName': 'Authorization',
            'where': 'header',
          },
        ],
        ...?extra,
      },
      validateStatus: validateStatus,
      contentType: [
        'application/octet-stream',
      ].first,
      cancelToken: cancelToken,
      onSendProgress: onSendProgress,
      onReceiveProgress: onReceiveProgress,
    );

    List<int> _bodyData;

    _bodyData = body;

    final _response = await _dio.request<dynamic>(
      _request.path,
      data: Stream.fromIterable(_bodyData.map((e) => [e])),
      options: _request,
    );

    return _response;
  }
  1. Oh no!

    You are trying to upload something other than an image. Please upload a .png, .jpg, .jpeg, .gif, .bmp, .tiff or .ico.

    Incoming!

    Drop your designs to start your upload.
Tasks
0
server returned results with length 1, expected length of 9

Linked items
0

Link issues together to show that they're related. Learn more.

Activity


Please register or sign in to reply
0 Assignees
None
Assign to
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
Due date
None
None
None
Time tracking
No estimate or time spent
Confidentiality
Not confidential
Not confidential

You are going to turn on confidentiality. Only project members with at least the Reporter role, the author, and assignees can view or be notified about this issue.

Lock issue
Unlocked
2
2 participants
Administrator
Kai
Reference:

Menu

Explore Projects Groups Snippets