-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.py
75 lines (54 loc) · 1.89 KB
/
upload.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
72
73
74
from kivymd.app import MDApp
from kivy.lang import Builder
from plyer import filechooser
from obs import ObsClient, CorsRule, Options
from datetime import datetime
# import huaweicloud
import boto3
import os
# from huaweicloudsdkobs.obs_client import ObsClient
from huaweicloudsdkcore.auth.credentials import BasicCredentials
# Replace these with your own values
endpoint = "http://obs.eu-west-101.myhuaweicloud.eu"
server="obs.eu-west-101.myhuaweicloud.eu"
access_key = "JAKGEFBQBLHWUNWWGIGI"
secret_key = "3lRysHwqAlRnw7kVFSWRCZFuIbdHau6UYHfzObz3"
bucket_name = "clothes"
expire_seconds = 3600
obsClient = ObsClient(access_key_id='', secret_access_key='', server='obs.eu-west-101.myhuaweicloud.eu')
kv="""
MDFloatLayout:
Image:
id: img
MDRaisedButton:
text: "Upload"
pos_hint: {"center_x": .5, "center_y": .4}
on_release:
app.file_chooser()
MDLabel:
id: selected_path
text:""
halign: "center"
"""
class FileChooser(MDApp):
def build(self):
return Builder.load_string(kv)
def file_chooser(self):
filechooser.open_file(on_selection=self.selected)
def selected(self, selection):
if selection:
self.root.ids.img.source = selection[0]
print(selection[0]) #è il path della foto selezionata
file_path = selection[0]
print(type(file_path))
#bucketClient = obsClient.bucketClient('clothes')
# Getting the current date and time
dt = datetime.now()
# getting the timestamp
ts = datetime.timestamp(dt)
# resp = bucketClient.putContent('top' + str(ts), file.read())
#resp = obsClient.putFile('clothes', 'top', file)
obsClient.putFile('clothes',str(ts), file_path)
#kivy_venv\Scripts\activate
if __name__ == "__main__":
FileChooser().run()