Home > front end >  Flutter data-raw in http PUT
Flutter data-raw in http PUT

Time:02-20

I have this sample code

curl --request PUT \
--url someurl/test.png \
--header 'AccessKey: MY_API_AccessKey' \
--header 'Content-Type: application/octet-stream' \
--data-binary @myimage.png

How do I get this done in Flutter?

CodePudding user response:

You did not mention where your image you are trying to upload does come from. So I supposed that is coming from local images. The code would then look the following (when using http package).

import 'package:http/http.dart';
void main() {
  // example when loading image from assets
  final image = Image.asset('graphics/background.png');
  put(Uri.parse('someurl/test.png'), headers: {
    'AccessKey': 'MY_API_AccessKey',
    'Content-Type': 'application/octet-stream'
  }, body: image.toByteData());

}
  • Related