27

I have created a flutter web project which uses network images and asset images, everything works fine when debugging on my pc but when I deploy it to a web server, the network images work fine but the asset images dont show at all. When I Inspect the page in the web browsers consol, I get the error below:

$1 @ window.dart:120
/assets/slack.png:1 Failed to load resource: the server responded with a status of 503 ()
window.dart:120 Error while trying to load an asset: Failed to load asset at "assets/slack.png" (503)

$1 @ window.dart:120
/assets/flutterLogo.png:1 Failed to load resource: the server responded with a status of 503 ()
window.dart:120 Error while trying to load an asset: Failed to load asset at "assets/flutterLogo.png" (503)

$1 @ window.dart:120
/assets/kross.jpg:1 Failed to load resource: the server responded with a status of 503 ()
window.dart:120 Error while trying to load an asset: Failed to load asset at "assets/kross.jpg" (503)

$1 @ window.dart:120
/assets/codingRocket2.png:1 Failed to load resource: the server responded 
Norbert
  • 6,874
  • 14
  • 40
  • 65

13 Answers13

14

You should perhaps check if the file is available as part of your deployment. 404 is the usual error code you received for resource not found. 503 is something related to the server availability or server errors. I would do the following.

Step 1. Check the build folder

Try running the flutter build web command in your project and inspect the build folder. Assuming a pubspec.yaml with following asset configurations.

  assets:
    - js/plotly_hookup.js
    - js/plotly-latest.min.js
    - images/
    - screen_shot.png

I would expect the following inside my build\web\assets folder.

Screen shot of build folder layout

If this is not working as shown, then its time to inspect the pubspec.yaml file and correct the paths.

Step 2: check your hosted folder

Ensure the files as shown above are available in your server where this folder is hosted. Also verify if the server has any configurations to be made specifically for image files or types of images files.

Abhilash Chandran
  • 6,803
  • 3
  • 32
  • 50
  • 2
    Hey man, didn't help. I checked all my files are there but the asset images are not showing up. – devDeejay Jul 06 '20 at 19:39
  • @devDeejay Can you check if this [answer](https://stackoverflow.com/a/62466271/3043944) helps you. There could be reasons how you access the asset image especially if you host the web app. – Abhilash Chandran Jul 07 '20 at 09:22
6

You should add photos to pubspec.yaml file and upload your assets folder to web server. Probably it is about not uploading folder

furkeen
  • 411
  • 5
  • 11
  • worked like a charm. I did not have to add them to `pubspec.yaml` tho. – Norbert Nov 15 '19 at 15:34
  • 3
    @Norbert hey this is not working out for me. I have my assets folder uploaded just fine with all the images declared in pubspec.yaml – devDeejay Jul 06 '20 at 19:31
  • 1
    I've added path to every image in pubspec.yaml, but it still isn't working. And what exactly did you mean, when you were saying *upload your assets folder to web server* ? – Mayur Agarwal Jun 21 '21 at 13:29
  • @MayurAgarwal when I answered this question Flutter Web is in beta stage so I don't know what happened in stable version. – furkeen Jun 21 '21 at 14:16
  • Ok, Should I move assets folder under web folder ? – Mayur Agarwal Jun 21 '21 at 14:19
  • To clarify, you should add your assets folder into your web folder. Make sure your pubspec.yaml references this web folder. – bm888 May 16 '23 at 14:14
6

Just do this with flutter 2.2.0 then you are all set.

flutter run -d chrome --web-port=8080  --web-renderer html //port is optional

Ahmed Sa'eed
  • 173
  • 2
  • 3
  • 12
Agoo Clinton
  • 611
  • 7
  • 3
6

Network Images are Failed to load When Run the Flutter Code on web browser. it’s because of HTML renderer issue.

you can run flutter code using following command or edit android studio settings for run .

flutter run -d chrome --web-renderer html

Two possible solution for Image Rendering Issue on Flutter web. Check it here https://youtu.be/U0Ez4CS6frc

Kamal Bunkar
  • 1,354
  • 1
  • 16
  • 20
6

Mine was perfectly working with development, when I deploy the build the logos were missing.

I fixed it by using HTML rendering while building the web assets

flutter build web --web-renderer html --release
AllwiN
  • 693
  • 2
  • 12
  • 26
  • I feel like this answer shouldn't have been here, since it's the complete opposite of the question... but it saved me. Thanks!!! – FoxDonut Mar 28 '23 at 17:21
  • IDK how you end up with your thought, op is looking for a solution to the missing assets file in his prod env, and that's the same one I encountered too.. anyway happy to help! – AllwiN Mar 29 '23 at 14:09
  • My apologies! I absolutely read your statement wrong. I misread "development" as deployed. I spent hours looking for a solution, so no doubt my brain wasn't functioning 100%. Thanks again! – FoxDonut Apr 08 '23 at 05:24
5

For Flutter Web 3.0:

your pubspec.yaml:

  assets:
    - assets/images/

test:

Image.asset("images/logo.png");

deploy:

Image.asset("assets/images/logo.png");

Worked for me!!!

The Gioi So
  • 51
  • 1
  • 3
  • 1
    I don't get it. Are you rewriting all your asset paths before deploying, then reverting back ? Why can the build auto-append the `assets/` prefix to the paths if that's the expected behavior ? – Adrien Lemaire Nov 26 '22 at 13:22
  • 1
    @TheGioiSo is onto something. I have my images in my pubspec.yaml defined as `- assets/images/` but when I do `flutter build web` I can see they end up placed in `assets/assets/images/`. If after building you go into the build folder and move the image files back down to their intended location at `assets/images/` it works as expected when deployed. This is probably an issue to raise with the team behind the flutter build tools if it hasn't been already. – Sound Conception Jun 05 '23 at 12:32
2

In my case there was a STRANGE (as there is no error in desktop or native mobile) error only in mobile browsers, so make sure check your deployed application with a remote debugger on chrome while you are connected to your mobile device.

chrome://inspect/#devices

a currently working solution ...

flutter build web --release --web-renderer canvaskit
Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 77d935af4d (7 weeks ago) • 2021-12-16 08:37:33 -0800
Engine • revision 890a5fca2e
Tools • Dart 2.15.1
HoseinGhanbari
  • 1,058
  • 1
  • 11
  • 23
1
  1. first check if the assets folder is in your web folder.
  2. while accessing the assets try it writing "assets" two times. for example - "assets/assets/slack.png"
1

You can solve the issue of asset images not showing up when deploying a flutter web project to a web server by following either of the two options:

  1. Run with: flutter run -d chrome --web-renderer html
  2. Add the following to web/index.html:
<script type="text/javascript">
    window.flutterWebRenderer = "html";
</script>

You can try either of the two options and see if it works for you.

0

In my case it was due to the permissions of the images in the asset folder. Right click on your webpage to inspect and click on Console

If you have the following message:

main.dart.js:7090          GET  
https://mywebsite.com/assets/images/Test/180229115.jpg 403 (Forbidden)

You might want to check permissions for your image files with ls -la on your server

I had the following:

-rwxr----- image1.jpg
-rwxr----- image2.jpg
-rwxr----- etc

Then change them to public read with:

chmod 644 *`

Output:

-rw-r--r-- image1.jpg
-rw-r--r-- image2.jpg
-rw-r--r-- etc

And reload your index.html, should now work!

Antonin GAVREL
  • 9,682
  • 8
  • 54
  • 81
0

In my case, the problem was I was using Image.network instead of Image.asset which did not cause an error when running locally as the images were viewed fine locally and only caused the images to not be viewed in deployment.

laila nabil
  • 135
  • 8
0

In my case I was also accessing the assets/assets folder. I have moved one level back, copying assets/assets/img -> assets/img and it has worked.

0

In my case I didn't realise the cAsE of the filenames on some of my images didn't match what I had in my code, so for example I had an image named assets/images/myimage.png, but I was referencing it as Image.asset('assets/images/MyImage.png'). This worked fine in development (I guess because the dev web server is NOT CASE SENSITIVE when serving files) but broke when I uploaded to my web server (Digital Ocean app platform - which I'm guessing IS case sensitive).

James Allen
  • 6,406
  • 8
  • 50
  • 83