首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何通过Dart/Flutter中的“application/octet-stream”将png文件发送到Microsoft Custom Vision?

在Dart/Flutter中,可以通过使用"application/octet-stream"将PNG文件发送到Microsoft Custom Vision。"application/octet-stream"是一种通用的二进制数据传输格式,可以用于发送任何类型的文件。

要将PNG文件发送到Microsoft Custom Vision,可以按照以下步骤进行操作:

  1. 首先,确保你已经安装了Dart/Flutter的相关开发环境,并且已经导入了与Microsoft Custom Vision API交互所需的相关库。
  2. 在Dart/Flutter中,可以使用http包来发送HTTP请求。首先,导入http包:
代码语言:txt
复制
import 'package:http/http.dart' as http;
  1. 创建一个函数,用于发送PNG文件到Microsoft Custom Vision。函数的参数应包括PNG文件的路径和Microsoft Custom Vision的API密钥。
代码语言:txt
复制
Future<void> sendPngToCustomVision(String filePath, String apiKey) async {
  // 读取PNG文件的内容
  List<int> pngBytes = await File(filePath).readAsBytes();

  // 构建HTTP请求
  var request = http.MultipartRequest(
    'POST',
    Uri.parse('https://customvision.ai/api/<YOUR_PROJECT_ID>/image'),
  );

  // 设置请求头,包括API密钥和内容类型
  request.headers['Prediction-Key'] = apiKey;
  request.headers['Content-Type'] = 'application/octet-stream';

  // 添加PNG文件的内容到请求体中
  request.files.add(
    http.MultipartFile.fromBytes(
      'image',
      pngBytes,
      filename: 'image.png',
    ),
  );

  // 发送请求并获取响应
  var response = await request.send();

  // 处理响应
  if (response.statusCode == 200) {
    // 请求成功
    print('PNG文件发送成功!');
  } else {
    // 请求失败
    print('PNG文件发送失败:${response.statusCode}');
  }
}
  1. 调用函数并传入PNG文件的路径和Microsoft Custom Vision的API密钥。
代码语言:txt
复制
String pngFilePath = '/path/to/image.png';
String customVisionApiKey = '<YOUR_CUSTOM_VISION_API_KEY>';

sendPngToCustomVision(pngFilePath, customVisionApiKey);

这样,你就可以通过Dart/Flutter中的"application/octet-stream"将PNG文件发送到Microsoft Custom Vision了。请注意,上述代码中的<YOUR_PROJECT_ID><YOUR_CUSTOM_VISION_API_KEY>需要替换为你自己的项目ID和API密钥。

关于Microsoft Custom Vision的更多信息,你可以访问腾讯云的相关产品介绍页面:腾讯云自定义视觉

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

  • Response.ContentType 所有类型

    大家好,又见面了,我是你们的朋友全栈君。‘ez’ => ‘application/andrew-inset’, ‘hqx’ => ‘application/mac-binhex40’, ‘cpt’ => ‘application/mac-compactpro’, ‘doc’ => ‘application/msword’, ‘bin’ => ‘application/octet-stream’, ‘dms’ => ‘application/octet-stream’, ‘lha’ => ‘application/octet-stream’, ‘lzh’ => ‘application/octet-stream’, ‘exe’ => ‘application/octet-stream’, ‘class’ => ‘application/octet-stream’, ‘so’ => ‘application/octet-stream’, ‘dll’ => ‘application/octet-stream’, ‘oda’ => ‘application/oda’, ‘pdf’ => ‘application/pdf’, ‘ai’ => ‘application/postscript’, ‘eps’ => ‘application/postscript’, ‘ps’ => ‘application/postscript’, ‘smi’ => ‘application/smil’, ‘smil’ => ‘application/smil’, ‘mif’ => ‘application/vnd.mif’, ‘xls’ => ‘application/vnd.ms-excel’, ‘ppt’ => ‘application/vnd.ms-powerpoint’, ‘wbxml’ => ‘application/vnd.wap.wbxml’, ‘wmlc’ => ‘application/vnd.wap.wmlc’, ‘wmlsc’ => ‘application/vnd.wap.wmlscriptc’, ‘bcpio’ => ‘application/x-bcpio’, ‘vcd’ => ‘application/x-cdlink’, ‘pgn’ => ‘application/x-chess-pgn’, ‘cpio’ => ‘application/x-cpio’, ‘csh’ => ‘application/x-csh’, ‘dcr’ => ‘application/x-director’, ‘dir’ => ‘application/x-director’, ‘dxr’ => ‘application/x-director’, ‘dvi’ => ‘application/x-dvi’, ‘spl’ => ‘application/x-futuresplash’, ‘gtar’ => ‘application/x-gtar’, ‘hdf’ => ‘application/x-hdf’, ‘js’ => ‘application/x-javascript’, ‘skp’ => ‘application/x-koan’, ‘skd’ => ‘application/x-koan’, ‘skt’ => ‘application/x-koan’, ‘skm’ => ‘application/x-koan’, ‘latex’ => ‘application/x-latex’, ‘nc’ => ‘application/x-netcdf’, ‘cdf’ => ‘application/x-netcdf’, ‘sh’ => ‘application/x-sh’, ‘shar’ => ‘application/x-shar’, ‘swf’ => ‘application/x-shockwave-flash’, ‘sit’ => ‘application/x-stuffit’, ‘sv4cpio’ => ‘application/x-sv4cpio’, ‘sv4crc’ => ‘application/x-sv4crc’, ‘tar’ => ‘application/x-tar’, ‘tcl’ => ‘application/x-tcl’, ‘tex’ => ‘application/x-tex’, ‘texinfo’ => ‘application/x-texinfo’, ‘texi’ => ‘application/x-texinfo’, ‘t’ => ‘application/x-troff’, ‘tr’ => ‘applica

    05

    content-type 的所有可选项

    ‘ez’        => ‘application/andrew-inset’,     ‘hqx’        => ‘application/mac-binhex40’,     ‘cpt’        => ‘application/mac-compactpro’,     ‘doc’        => ‘application/msWord’,     ‘bin’        => ‘application/octet-stream’,     ‘dms’        => ‘application/octet-stream’,     ‘lha’        => ‘application/octet-stream’,     ‘lzh’        => ‘application/octet-stream’,     ‘exe’        => ‘application/octet-stream’,     ‘class’        => ‘application/octet-stream’,     ‘so’        => ‘application/octet-stream’,     ‘dll’        => ‘application/octet-stream’,     ‘oda’        => ‘application/oda’,     ‘pdf’        => ‘application/pdf’,     ‘ai’        => ‘application/postscript’,     ‘eps’        => ‘application/postscript’,     ‘ps’        => ‘application/postscript’,     ‘smi’        => ‘application/smil’,     ‘smil’        => ‘application/smil’,     ‘mif’        => ‘application/vnd.mif’,     ‘xls’        => ‘application/vnd.ms-Excel’,     ‘ppt’        => ‘application/vnd.ms-Powerpoint’,     ‘wbxml’        => ‘application/vnd.wap.wbxml’,     ‘wmlc’        => ‘application/vnd.wap.wmlc’,     ‘wmlsc’        => ‘application/vnd.wap.wmlscriptc’,     ‘bcpio’        => ‘application/x-bcpio’,     ‘vcd’        => ‘application/x-cdlink’,     ‘pgn’        => ‘application/x-chess-pgn’,     ‘cpio’        => ‘application/x-cpio’,     ‘csh’        => ‘application/x-csh’,     ‘dcr’        => ‘application/x-Director’,     ‘dir’        => ‘application/x-director’,     ‘dxr’        => ‘application/x-director’,     ‘dvi’        => ‘application/x-dvi’,     ‘spl’        => ‘application/x-futuresplash’,     ‘gtar’        => ‘application/x-gtar’,     ‘hdf’        => ‘application/x-hdf’,     ‘js’        => ‘application/x-javascript’,     ‘skp’        => ‘application/x-koan’,     ‘skd’        => ‘application/x-koan’,     ‘skt’        => ‘application/x-koan’,     ‘skm’        => ‘application/x-koan’,     ‘latex’        => ‘application/x-latex’,     ‘nc’        => ‘application/x-netcdf’,     ‘

    02
    领券