Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/firebase_storage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.0.3

* Fix inconsistency of `getPath`, on Android the path returned started with a `/` but on iOS it did not
* Fix content-type auto-detection on Android

## 3.0.2

* Automatically use version from pubspec.yaml when reporting usage to Firebase.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import android.net.Uri;
import android.util.SparseArray;
import android.webkit.MimeTypeMap;
import androidx.annotation.NonNull;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
Expand Down Expand Up @@ -49,7 +50,7 @@ private FirebaseStoragePlugin(MethodChannel channel, Registrar registrar) {
}

@Override
public void onMethodCall(MethodCall call, final Result result) {
public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result) {
String app = call.argument("app");
String storageBucket = call.argument("bucket");
if (app == null && storageBucket == null) {
Expand Down Expand Up @@ -258,15 +259,13 @@ public void onFailure(@NonNull Exception e) {
private void putFile(MethodCall call, Result result) {
String filename = call.argument("filename");
String path = call.argument("path");
Map<String, Object> metadata = call.argument("metadata");
File file = new File(filename);
final Uri fileUri = Uri.fromFile(file);
Map<String, Object> metadata = call.argument("metadata");
metadata = ensureMimeType(metadata, fileUri);

StorageReference ref = firebaseStorage.getReference().child(path);
UploadTask uploadTask;
if (metadata == null) {
uploadTask = ref.putFile(Uri.fromFile(file));
} else {
uploadTask = ref.putFile(Uri.fromFile(file), buildMetadataFromMap(metadata));
}
final UploadTask uploadTask = ref.putFile(fileUri, buildMetadataFromMap(metadata));
final int handle = addUploadListeners(uploadTask);
result.success(handle);
}
Expand Down Expand Up @@ -394,7 +393,7 @@ private void cancelUploadTask(MethodCall call, final Result result) {
}
}

private void resumeUploadTask(MethodCall call, final Result result) {
private void resumeUploadTask(MethodCall call, @NonNull final Result result) {
int handle = call.argument("handle");
UploadTask task = uploadTasks.get(handle);
if (task != null) {
Expand Down Expand Up @@ -487,4 +486,25 @@ private Map<String, Object> buildMapFromTaskSnapshot(
}
return map;
}

private Map<String, Object> ensureMimeType(Map<String, Object> metadata, Uri file) {
if (metadata == null) {
metadata = new HashMap<>();
}

if (metadata.get("contentType") == null) {
metadata.put("contentType", getMimeType(file));
}

return metadata;
}

private static String getMimeType(Uri file) {
String type = null;
String extension = MimeTypeMap.getFileExtensionFromUrl(file.toString());
if (extension != null) {
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
}
return type;
}
}
2 changes: 1 addition & 1 deletion packages/firebase_storage/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies:
firebase_storage:
path: ../
firebase_core: ^0.4.0
uuid: "^1.0.0"
uuid: ^1.0.0
http: ^0.12.0

dev_dependencies:
Expand Down
8 changes: 7 additions & 1 deletion packages/firebase_storage/lib/src/storage_reference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,18 @@ class StorageReference {
/// Returns the full path to this object, not including the Google Cloud
/// Storage bucket.
Future<String> getPath() async {
return await FirebaseStorage.channel
final String path = await FirebaseStorage.channel
.invokeMethod<String>("StorageReference#getPath", <String, String>{
'app': _firebaseStorage.app?.name,
'bucket': _firebaseStorage.storageBucket,
'path': _pathComponents.join("/"),
});

if (path.startsWith('/')) {
return path.substring(1);
} else {
return path;
}
}

/// Returns the short name of this object.
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_storage/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Firebase Cloud Storage, a powerful, simple, and
cost-effective object storage service for Android and iOS.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_storage
version: 3.0.2
version: 3.0.3

flutter:
plugin:
Expand Down