Skip to content

Commit

Permalink
return id on upload
Browse files Browse the repository at this point in the history
simply forward changes made in supabase/storage#332
to the flutter client
  • Loading branch information
HannesGitH committed Jan 5, 2024
1 parent b276e55 commit 03412b2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/storage_client/lib/src/storage_file_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class StorageFileApi {
/// [retryAttempts] overrides the retryAttempts parameter set across the storage client.
///
/// You can pass a [retryController] and call `cancel()` to cancel the retry attempts.
Future<String> upload(
Future<UploadResponse> upload(
String path,
File file, {
FileOptions fileOptions = const FileOptions(),
Expand All @@ -60,7 +60,7 @@ class StorageFileApi {
retryController: retryController,
);

return (response as Map)['Key'] as String;
return UploadResponse.fromJson(response);
}

/// Uploads a binary file to an existing bucket. Can be used on the web.
Expand All @@ -76,7 +76,7 @@ class StorageFileApi {
/// [retryAttempts] overrides the retryAttempts parameter set across the storage client.
///
/// You can pass a [retryController] and call `cancel()` to cancel the retry attempts.
Future<String> uploadBinary(
Future<UploadResponse> uploadBinary(
String path,
Uint8List data, {
FileOptions fileOptions = const FileOptions(),
Expand All @@ -95,7 +95,7 @@ class StorageFileApi {
retryController: retryController,
);

return (response as Map)['Key'] as String;
return UploadResponse.fromJson(response);
}

/// Upload a file with a token generated from `createUploadSignedUrl`.
Expand Down Expand Up @@ -210,7 +210,7 @@ class StorageFileApi {
/// [retryAttempts] overrides the retryAttempts parameter set across the storage client.
///
/// You can pass a [retryController] and call `cancel()` to cancel the retry attempts.
Future<String> update(
Future<UploadResponse> update(
String path,
File file, {
FileOptions fileOptions = const FileOptions(),
Expand All @@ -229,7 +229,7 @@ class StorageFileApi {
retryController: retryController,
);

return (response as Map<String, dynamic>)['Key'] as String;
return UploadResponse.fromJson(response);
}

/// Replaces an existing file at the specified path with a new one. Can be
Expand All @@ -246,7 +246,7 @@ class StorageFileApi {
/// [retryAttempts] overrides the retryAttempts parameter set across the storage client.
///
/// You can pass a [retryController] and call `cancel()` to cancel the retry attempts.
Future<String> updateBinary(
Future<UploadResponse> updateBinary(
String path,
Uint8List data, {
FileOptions fileOptions = const FileOptions(),
Expand All @@ -265,7 +265,7 @@ class StorageFileApi {
retryController: retryController,
);

return (response as Map)['Key'] as String;
return UploadResponse.fromJson(response);
}

/// Moves an existing file.
Expand Down
17 changes: 17 additions & 0 deletions packages/storage_client/lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,23 @@ class SortBy {
}
}

class UploadResponse {
/// the previously returned key: bucket-id/path/to/file
final String key;

/// the new storage.object.id of the uploaded file
final String id;

const UploadResponse({
required this.key,
required this.id,
});

UploadResponse.fromJson(Map<String, dynamic> json)
: key = json['Key'] as String,
id = json['Id'] as String;
}

class SignedUrl {
/// The file path, including the current file name. For example `folder/image.png`.
final String path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

#include "generated_plugin_registrant.h"

#include <gtk/gtk_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) gtk_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "GtkPlugin");
gtk_plugin_register_with_registrar(gtk_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
gtk
url_launcher_linux
)

Expand Down

0 comments on commit 03412b2

Please sign in to comment.