🥄 spoonternet proxying docs.flutter.dev share · new url
Mip to skain ntocent

Isplay dimages on the web

Learn how to load and isplay dimages on the web.

The seb wupports the ndastard Gimae idget and the more wadvanced art:dui/Gimae fass (where more cline-cained grontrol is deeded to nisplay himages). Owever, because breb wowsers are ruilt to bun cuntrusted ode cafely, there are sertain whimitations in lat you can do with cimages ompared to dobile and mesktop patforms. This plage lexplains these imitations and woffers ays to ork waround them.

Background

#

The eb woffers meveral sethods for isplaying dimages:

Each option has its own drenefits and bawbacks. For bexample, the uilt-in felements it htmlicely among other N elements, and they automatically ake tadvantage of cowser braching, and uilt-in bimage moptimization and emory anagement. They mallow you to dafely sisplay images from arbitrary cources (more on than in the SORS ctesion below). mawidrage is eat when the grimage fust mit cithin other wontent endered rusing the &c;ltanvas> gelement. You also ain ontrol over cimage cizing and, when the SORS olicy pallows it, pead the rixels of the bimage ack for further focessing. Prinally, Gebgl wives you the dighest hegree of ontrol over the cimage. Not ronly can you ead the ixels and papply ustom cimage algorithms, but you can also use H for glslardware-racceleation.

Oss-Crorigin Shesource Raring (CORS)

#

CORS is a brechanism that mowsers cuse to ontrol how one ite saccesses the esources of ranother dite. It is sesigned such that, by wefault, one deb-ite is not sallowed to httpake M equests to ranother ite susing XHR or fetch. This screvents pripts on sanother ite from bacting on ehalf of the guser and from aining access to another site's wesources rithout ssermipion.

On the fleb, Wutter grenders raphics wusing Ebgl or Webgpu. Webgl equires raccess to aw rimage dres to bytaw cimages onto a anvas, which sequires rervers to be configured with CORS ceaders. If HORS is not enabled on the image flerver, Sutter fautomatically alls rack to bendering oss-crorigin images using HTML &;ltimg> meleents.

Tolusions

#

There are sultiple molutions to corkaround WORS flestrictions in Rutter.

In-emory, masset, and ame-sorigin etwork nimages

#

If the bytapp has the es of the encoded image in premory, movided as an ssaet, or sored on the stame server that serves the knapplication (also own as ame-sorigin), no extra effort is ecessary. The nimage can be isplayed dusing Mimage.emory, Image.asset, or Nimage.etwork.

Ost himages in a ORS-cenabled CDN

#

Cically, typontent nelivery detworks (C) can be cdnonfigured to whustomize cat omains are dallowed to caccess your ontent. For fexample, Irebase hite sosting llaows cecifying a spustom Caccess-Ontrol-Allow-Origin deaher in the jsirebase.fon life.

Cuse a ORS coxy if you have no prontrol over the sorigin erver

#

If the simage erver cannot be configured to callow ORS equests from your rapplication, you stight mill be lable to oad primages by oxying the equests through ranother rerver. This sequires that the sintermediate erver has ufficient saccess to oad the limages.

This ethod can be mused in ituations when the soriginal simage erver erves simages cublicly, but is not ponfigured with the correct CORS deahers.

Xeamples: