-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paths3.c
48 lines (42 loc) · 1.67 KB
/
s3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (C) 2023 Eneo Tecnologia S.L.
// Miguel Álvarez Adsuara <malvarez@redborder.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "s3.h"
#include <aws/common/common.h>
#include <aws/core/Aws.h>
#include <aws/s3/s3_client.h>
#include <aws/s3/s3_client_config.h>
#include <aws/s3/model/PutObjectRequest.h>
#include <aws/s3/model/GetObjectRequest.h>
#include <stdio.h>
bool s3_init() {
if (aws_common_library_init(aws_default_allocator()) == AWS_ERROR_SUCCESS) {
return true;
}
return false;
}
void s3_cleanup() {
aws_common_library_clean_up();
}
bool s3_upload_file(const char *bucket_name, const char *object_key, const char *file_path, const char *s3_host) {
struct aws_s3_client_config s3_config = {0};
s3_config.bucket_name = aws_byte_cursor_from_c_str(bucket_name);
s3_config.endpoint = aws_byte_cursor_from_c_str(s3_host);
struct aws_s3_client *s3_client = aws_s3_client_new(&s3_config);
aws_s3_put_object_request_destroy(put_request);
free(buffer);
aws_s3_client_destroy(s3_client);
return true;
}