0

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

5
  • You are telling the server you will send an 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 ... Commented Jul 3, 2021 at 14:22
  • @derpirscher i tried file.readAsBytes(). but still error Bad request. Thanks for response. Commented Jul 4, 2021 at 18:27
  • @derpirscher tried this also solution from Stack overflow. file uploaded sucessfully but i got only dot pixel. check this link my firebase storage Commented Jul 4, 2021 at 19:05
  • @derpirscher 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. Commented Jul 5, 2021 at 8:18
  • Well, this may be an issue with the emulator then, if it's behaving differently from the firebase server. I never used either of them, so I can't really help you there. My hint was just the obvious inconsistency in your original request. Commented Jul 5, 2021 at 8:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.