When I try to upload a image to server from Flutter, this error occurres. I don't know how to pass the file to HTTP POSST method, but I took the image and got the file path using the image_picker
plugin.
my file path is
:I/flutter ( 9123): File: '/storage/emulated/0/Android/data/com.example.myapp/files/Pictures/2798d03d-2c6b-4f80-8198-94866dfc45962028103221680196242.jpg'
my POST method is like ;
var response = await
http.post("http://206.189.92.174:4000/API/Posts/Cube_Post_Submit",
body :
{
'attachments' : files ,
'User_Id' : "5acc5d6e1295332c28f7e205",
'Cubes_Id' : jsonstring,
'Post_Text' : "hello",
'Post_Category' : "Story",
'Post_Link': ""
}
);
print(response.body);
error will be like this :
[ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception: E/flutter ( 9123): type '_File' is not a subtype of type 'String' in type cast E/flutter ( 9123): #0 Object._as (dart:core/runtime/libobject_patch.dart:74:25) E/flutter ( 9123): #1
CastMap.forEach. (dart:_internal/cast.dart:323:25) E/flutter ( 9123): #2
__InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.forEach (dart:collection/runtime/libcompact_hash.dart:365:8) E/flutter ( 9123): #3 CastMap.forEach (dart:_internal/cast.dart:322:13)
http.
fromhttp.post
come from? Please add the import to your question. – Günter Zöchbauerfiles
come from? – Günter Zöchbauer