ERP-Ukraine / odoo-rpc-dart

Odoo RPC Library for Dart
MIT License
43 stars 32 forks source link

cant able to get binary data ...instead showing size of the file #39

Open shameemalim opened 1 year ago

shameemalim commented 1 year ago

i am trying to get datas from ir.attachment but instead of base64 i'm getting only size of the file

lem8r commented 1 year ago

Are you setting bin_size=True in the context? Which field of ir.attachment are you reading?

shameemalim commented 1 year ago

i m reading 'datas' field.. i tried with bin_size=True and bin_size=False both

shameemalim commented 1 year ago

any hope?

BARSHA-ABHILASHA commented 1 day ago

List attachmentIds = []; if (_attachmentResult != null && _attachmentResult!.files.isNotEmpty) { final attachmentInfo = _attachmentResult!.files.first; print('Selected attachmentInfo: $attachmentInfo');

   final attachmentData = attachmentInfo.bytes ??
        await File(attachmentInfo.path!).readAsBytes();
    print('Read attachmentData: $attachmentData');

    if (attachmentData != null) {
      final attachment = await orpc?.callKw({
        'model': 'ir.attachment',
        'method': 'create',
        'args': [
          {
            'name': attachmentInfo.name,
            'type': 'binary',
            'datas': base64Encode(attachmentData),
            'res_model': 'crm.lead',
            'res_id': widget.messageId,
            'mimetype': attachmentInfo.extension != null
                ? 'application/${attachmentInfo.extension}'
                : 'application/octet-stream',
          }
        ],
        'kwargs': {
          'context': {'bin_size': true}
        },
      });

      print('Created attachment with ID: $attachment');
      attachmentIds.add(attachment);
    } else {
      print('Failed to read attachment data.');
    }
  } else {
    print('No attachment selected.');
  }

  print('Creating message...');
  final message = await orpc?.callKw({
    'model': 'mail.message',
    'method': 'create',
    'args': [
      {
        'model': 'crm.lead',
        'body': _responseController.text,
        'res_id': widget.messageId,
        'message_type': 'comment',
        'subtype_id': 1,
        'attachment_ids': attachmentIds.isNotEmpty
            ? [
                [6, 0, attachmentIds]
              ]
            : [],
      }
    ],
    'kwargs': {
      'context': {'bin_size': true}
    },
  });

  if (message != null) {
    print('Created message with ID: $message');
    _responseController.clear();
    setState(() {
      _attachmentResult = null;
    });
    fetchResponse(); // Refresh the messages list
  }

  check this one  use filepicker for this 
BARSHA-ABHILASHA commented 1 day ago

any hope?

once check the code i mentioned