Flutter 无法使用文件头检测图像文件格式。图片来源:编码后的图片字节

问题描述 投票:0回答:1

我有一个 django 服务器,其中有由 nginx 提供的媒体,我正在尝试将媒体加载到我的 flutter 应用程序中:

Image.network(
              valueOrDefault<String>(
                  FFAppState().user.photo,
                       'https://stpeterlibrary.crabdance.com/static/images/LOGO%201.png',
              )

来自同一站点的静态图像加载得很好,但网络图像根本不加载,并给我这个错误:

Failed to detect image file format using the file header.
File header was [0x3c 0x21 0x44 0x4f 0x43 0x54 0x59 0x50 0x45 0x20].
Image source: encoded image bytes

静态文件位于images/LOGO%201.png 在页面加载照片之前显示,如果照片为空,即使它正在工作,它也会显示相同的错误。 我认为该错误与正在加载图像的小部件有关

Padding(
          padding: EdgeInsetsDirectional.fromSTEB(16.0, 16.0, 16.0, 16.0),
          child: InkWell(
            splashColor: Colors.transparent,
            focusColor: Colors.transparent,
            hoverColor: Colors.transparent,
            highlightColor: Colors.transparent,
            onTap: () async {
              await Navigator.push(
                context,
                PageTransition(
                  type: PageTransitionType.fade,
                  child: FlutterFlowExpandedImageView(
                    image: Image.network(
                      valueOrDefault<String>(
                        FFAppState().user.photo,
                        'https://stpeterlibrary.crabdance.com/static/images/LOGO%201.png',
                      ),
                      fit: BoxFit.contain,
                    ),
                    allowRotation: false,
                    tag: valueOrDefault<String>(
                      FFAppState().user.photo,
                      'https://stpeterlibrary.crabdance.com/static/images/LOGO%201.png',
                    ),
                    useHeroAnimation: true,
                  ),
                ),
              );
            },
            child: Hero(
              tag: valueOrDefault<String>(
                FFAppState().user.photo,
                'https://stpeterlibrary.crabdance.com/static/images/LOGO%201.png',
              ),
              transitionOnUserGestures: true,
              child: ClipRRect(
                borderRadius: BorderRadius.circular(12.0),
                child: Image.network(
                  valueOrDefault<String>(
                    FFAppState().user.photo,
                    'https://stpeterlibrary.crabdance.com/static/images/LOGO%201.png',
                  ),
                  width: MediaQuery.of(context).size.width * 1.0,
                  height: 230.0,
                  fit: BoxFit.contain,
                ),
              ),
            ),
          ),
        ),
django flutter django-rest-framework
1个回答
0
投票

问题是我的 API 会以这种形式提供图像链接:

stpeterlibrary.crabdance.com/media/media_file.jpg

这在某种程度上导致了 Image.network(url) 的错误,并添加了 https://

https://stpeterlibrary.crabdance.com/media/media_file.jpg

成功了。

© www.soinside.com 2019 - 2024. All rights reserved.