Last active
September 22, 2020 03:41
-
-
Save adamcyber1/4b2c593fee77ce4524d424d5c720ea42 to your computer and use it in GitHub Desktop.
Doogle Grive upload
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
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