Search code examples
flutterdartdio

type 'UploadFileInfo' is not a subtype of type 'String' in type cast


Image Reference

I am trying to upload a file in flutter using HTTP package with some parameters and some headers. But it's occurring a problem in UploadFileInfo. this is my actual exception:

" type 'UploadFileInfo' is not a subtype of type 'String' in type cast "


Solution

  • The ContentType you're using

    application/x-www-form-urlencoded 
    

    is used for encoded strings like:

    field1=value1&field2=value2
    

    For usage with FormData the ContentType you need should be

    multipart/form-data
    

    as a content type.

    But, as far as I know Dio is smart enough to understand it, so you could try omitting the ContentType header too!