Skip to content

Instantly share code, notes, and snippets.

@ShivamGoyal1899
Created June 12, 2019 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShivamGoyal1899/95712f3fe36f05ca9c47c247d507a3b3 to your computer and use it in GitHub Desktop.
Save ShivamGoyal1899/95712f3fe36f05ca9c47c247d507a3b3 to your computer and use it in GitHub Desktop.
Future<String> uploadMediaItem(File image) async {
// Get the filename of the image
final String filename = path.basename(image.path);
// Set up the headers required for this request.
final Map<String, String> headers = <String,String>{};
headers.addAll(await _authHeaders);
headers['Content-type'] = 'application/octet-stream';
headers['X-Goog-Upload-Protocol'] = 'raw';
headers['X-Goog-Upload-File-Name'] = filename;
// Make the HTTP request to upload the image. The file is sent in the body.
return http
.post(
'https://photoslibrary.googleapis.com/v1/uploads',
body: image.readAsBytesSync(),
headers: await _authHeaders,
)
.then((Response response) {
if (response.statusCode != 200) {
print(response.reasonPhrase);
print(response.body);
}
return response.body;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment