static Future<String> uploadPic(File image) async {
String fileName = DateTime.now().millisecondsSinceEpoch.toString();
const signer = AWSSigV4Signer();
final scope = AWSCredentialScope(
region: "eeur",
service: AWSService.s3,
);
const host = '{{accountid}}.r2.cloudflarestorage.com';
final serviceConfiguration = S3ServiceConfiguration();
final path = '/{{bucketname}}/$fileName.jpg';
final uploadRequest = AWSStreamedHttpRequest.put(
Uri.https(host, path),
body: image.openRead(),
headers: {
AWSHeaders.host: host,
AWSHeaders.contentType: 'image/jpg',
},
);
final signedUploadRequest = await signer.sign(
uploadRequest,
credentialScope: scope,
serviceConfiguration: serviceConfiguration,
);
final uploadResponse = await signedUploadRequest.send().response;
final uploadStatus = uploadResponse.statusCode;
if (uploadStatus == 200) {
return "{{public_link_to_image}}";
}
throw Exception("there was an error uploading the image");
}
static Future<String> uploadPic(File image) async {
String fileName = DateTime.now().millisecondsSinceEpoch.toString();
const signer = AWSSigV4Signer();
final scope = AWSCredentialScope(
region: "eeur",
service: AWSService.s3,
);
const host = '{{accountid}}.r2.cloudflarestorage.com';
final serviceConfiguration = S3ServiceConfiguration();
final path = '/{{bucketname}}/$fileName.jpg';
final uploadRequest = AWSStreamedHttpRequest.put(
Uri.https(host, path),
body: image.openRead(),
headers: {
AWSHeaders.host: host,
AWSHeaders.contentType: 'image/jpg',
},
);
final signedUploadRequest = await signer.sign(
uploadRequest,
credentialScope: scope,
serviceConfiguration: serviceConfiguration,
);
final uploadResponse = await signedUploadRequest.send().response;
final uploadStatus = uploadResponse.statusCode;
if (uploadStatus == 200) {
return "{{public_link_to_image}}";
}
throw Exception("there was an error uploading the image");
}