-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (56 loc) · 2.38 KB
/
main.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sys
import boto3
import os
from PyQt5.QtCore import QFileInfo
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QPushButton, QListWidget, QLabel, QFileDialog, \
QDialog, QWidget, QTableWidgetItem, QTableWidget
# Define your AWS credentials and S3 bucket name
aws_access_key_id = 'dere'
aws_secret_access_key = 'boyu'
bucket_name = 'kavaklar'
# Create an S3 client
s3 = boto3.client('s3', aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)
class CloudStorageApp(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Cloud Storage App")
self.setGeometry(100, 100, 800, 600)
self.central_widget = QWidget(self)
self.setCentralWidget(self.central_widget)
self.layout = QVBoxLayout()
self.central_widget.setLayout(self.layout)
self.upload_button = QPushButton("Upload File")
self.upload_button.clicked.connect(self.upload_file)
self.layout.addWidget(self.upload_button)
self.content_panel = QTableWidget()
self.content_panel.setColumnCount(1) # One column for file names
self.content_panel.setHorizontalHeaderLabels(["File Name"])
self.layout.addWidget(self.content_panel)
self.refresh_button = QPushButton("Refresh")
self.refresh_button.clicked.connect(self.list_files)
self.layout.addWidget(self.refresh_button)
self.list_files()
def upload_file(self):
file_dialog = QFileDialog()
file_path, _ = file_dialog.getOpenFileName()
if file_path:
file_name = QFileInfo(file_path).fileName()
s3.upload_file(file_path, bucket_name, file_name)
self.list_files()
def list_files(self):
response = s3.list_objects_v2(Bucket=bucket_name)
if 'Contents' in response:
file_list = [obj['Key'] for obj in response['Contents']]
self.update_content_panel(file_list)
else:
self.update_content_panel([])
def update_content_panel(self, file_list):
self.content_panel.setRowCount(len(file_list))
for row, file_name in enumerate(file_list):
item = QTableWidgetItem(file_name)
self.content_panel.setItem(row, 0, item)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = CloudStorageApp()
window.show()
sys.exit(app.exec_())