final appDocDir = await getApplicationDocumentsDirectory(); final filePath = "${appDocDir.absolute}/path/to/mountains.jpg"; final file = File(filePath); // Create the file metadata final metadata = SettableMetadata(contentType: "image/jpeg"); // Create a reference to the Firebase Storage bucket final storageRef = FirebaseStorage.instance.ref(); // Upload file and metadata to the path 'images/mountains.jpg' final uploadTask = storageRef .child("images/path/to/mountains.jpg") .putFile(file, metadata); // Listen for state changes, errors, and completion of the upload. uploadTask.snapshotEvents.listen((TaskSnapshot taskSnapshot) { switch (taskSnapshot.state) { case TaskState.running: final progress = 100.0 * (taskSnapshot.bytesTransferred / taskSnapshot.totalBytes); print("Upload is $progress% complete."); break; case TaskState.paused: print("Upload is paused."); break; case TaskState.canceled: print("Upload was canceled"); break; case TaskState.error: // Handle unsuccessful uploads break; case TaskState.success: // Handle successful uploads on complete // ... break; } });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter