putObject method
Uploads raw bytes to S3 using PUT.
Optional contentType and canned acl values are added as request
headers when provided.
Returns true when the upload succeeds with status code 200.
Example:
final ok = await client.putObject(
key: 'uploads/avatar.png',
data: Uint8List.fromList([1, 2, 3]),
contentType: 'image/png',
acl: S3Acl.publicRead,
);
Implementation
Future<bool> putObject({required String key, required Uint8List data, String? contentType, S3Acl? acl}) async {
try {
final headers = <String, String>{};
if (contentType != null) {
headers['content-type'] = contentType;
}
if (acl != null) {
headers['x-amz-acl'] = acl.value;
}
final response = await _makeRequest(method: 'PUT', path: key, body: data, extraHeaders: headers);
return response.statusCode == 200;
} catch (e) {
return false;
}
}