I try to upload image to Firebase local storage emulator from flutter desktop software. I'm using file_selector_windows plugin for file selection.
void _openImageFile() async {
final typeGroup = XTypeGroup(
label: 'images',
extensions: ['jpg', 'png'],
);
final files = await FileSelectorPlatform.instance
.openFiles(acceptedTypeGroups: [typeGroup]);
final file = files[0];
final fileName = file.name;
final filePath = file.path;
final responseFireStorage = await http.post(
Uri.parse('http://localhost:9199/v0/b/default-bucket/o?name=sample.jpg'),
headers: <String, String>{
'Content-Type': 'image/jpeg',
},
body: filePath,
);
print(responseFireStorage.statusCode);
}
Error: 400 BadRequest
image/jpeg, yet you are just sending a string (the path of the file) ... You may need to add the file content to the post request ...final responseFireStore = await http.post( Uri.parse( 'https://firebasestorage.googleapis.com/v0/b/coun-ab246.appspot.com/o?name=avatar.jpg'), headers: <String, String>{ 'Content-Type': 'image/jpeg', }, body: File(filePath).readAsBytesSync().buffer.asUint8List(), );i tried this working well, i got picture in firebase storage. this not working in firebase local emulator showing bad request.