Skip to content

Instantly share code, notes, and snippets.

@adamcyber1
Last active September 22, 2020 03:41
Show Gist options
  • Save adamcyber1/4b2c593fee77ce4524d424d5c720ea42 to your computer and use it in GitHub Desktop.
Save adamcyber1/4b2c593fee77ce4524d424d5c720ea42 to your computer and use it in GitHub Desktop.
Doogle Grive upload
void uploadFile() async {
File file = await FilePicker.getFile();
AuthUser user = await Amplify.Auth.getCurrentUser();
try {
if (file.existsSync()) {
setState(() {
uploading = true;
});
final key = user.username + '/' + file.path.split('/').last;
await Amplify.Storage.uploadFile(key: key, local: file);
// log an upload event, tracking the amount of bytes uploaded
AnalyticsEvent event = AnalyticsEvent("file_upload_event");
event.properties.addStringProperty("user", user.username);
event.properties.addIntProperty("file_size", file.lengthSync());
Amplify.Analytics.recordEvent(event: event);
Amplify.Analytics.flushEvents();
setState(() {
uploading = false;
});
}
} catch (e) {
Alert(
context: context,
type: AlertType.error,
desc: "Error Uploading File: " + e.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment