uploadBlob method
upload a blob to the server
if serverUrls
is null, the userServerList is fetched from nostr.
if the pukey has no UserServerList (kind: 10063), throws an error
the current signer is used to sign the request
strategy
is the upload strategy, default is mirrorAfterSuccess
serverMediaOptimisation
is whether the server should optimise the media BUD-05
, IMPORTANT: the server hash will be different \
Implementation
Future<List<BlobUploadResult>> uploadBlob({
required Uint8List data,
List<String>? serverUrls,
String? contentType,
UploadStrategy strategy = UploadStrategy.mirrorAfterSuccess,
bool serverMediaOptimisation = false,
}) async {
final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
/// sha256 of the data
final dataSha256 = sha256.convert(data);
_checkSigner();
final Nip01Event myAuthorization = Nip01Event(
content: "upload",
pubKey: _signer.getPublicKey(),
kind: kBlossom,
createdAt: now,
tags: [
["t", "upload"],
["x", dataSha256.toString()],
["expiration", "${now + BLOSSOM_AUTH_EXPIRATION.inMilliseconds}"],
],
);
await _signer.sign(myAuthorization);
serverUrls ??= await _userServerList
.getUserServerList(pubkeys: [_signer.getPublicKey()]);
if (serverUrls == null) {
throw Exception("User has no server list");
}
return _blossomImpl.uploadBlob(
data: data,
serverUrls: serverUrls,
authorization: myAuthorization,
contentType: contentType,
strategy: strategy,
mediaOptimisation: serverMediaOptimisation,
);
}