createBlobUrl static method

String createBlobUrl(
  1. Uint8List bytes
)

Creates a Blob URL from the given bytes with the correct MIME type.

Implementation

static String createBlobUrl(Uint8List bytes) {
  final fileType = FileMagicNumber.detectFileTypeFromBytes(bytes);
  String type = '';

  switch (fileType) {
    case FileMagicNumberType.pdf:
      type = 'application/pdf';
      break;
    case FileMagicNumberType.png:
      type = 'image/png';
      break;
    case FileMagicNumberType.jpg:
      type = 'image/jpeg';
      break;
    case FileMagicNumberType.heic:
      type = 'image/heic';
      break;
    default:
      type = 'application/octet-stream';
  }

  final blob = web.Blob([bytes.toJS].toJS, web.BlobPropertyBag(type: type));
  return web.URL.createObjectURL(blob);
}