Created
June 12, 2019 11:06
-
-
Save ShivamGoyal1899/95712f3fe36f05ca9c47c247d507a3b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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