def service():
    return oss2.Service(
        oss2.Auth('fake-access-key-id', 'fake-access-key-secret'),
        'http://oss-cn-hangzhou.aliyuncs.com')
示例#2
0
from aliyunsdkcore import client
import oss2
from aliyunsdkcore.profile import region_provider
import json

auth = oss2.Auth('LTAIruyemIEd4LeQ', 'DRZbgui8rT0kAiP0kAJJGrxffIA3DJ')

service = oss2.Service(auth, 'http://oss-cn-hangzhou.aliyuncs.com')

print([b.name for b in oss2.BucketIterator(service)])
示例#3
0
def ossUpload(remoteFile, localFile):
    service = oss2.Service(auth, endpoint)
    bucket = oss2.Bucket(auth, endpoint, bucketName)

    bucket.put_object_from_file(remoteFile, localFile)
示例#4
0
    if object_exist:
        return True
    else:
        return False

if __name__ == "__main__":
    bucket_name = sys.argv[1]
    path = sys.argv[2]
    old_version = sys.argv[3]
    new_version = sys.argv[4]
    war_name = sys.argv[5]
    AccessKeyId = sys.argv[6]
    AccessKeySecret = sys.argv[7]

    auth = oss2.Auth(AccessKeyId, AccessKeySecret)
    service = oss2.Service(auth, 'oss-cn-qingdao.aliyuncs.com')
    bucket = oss2.Bucket(auth, 'http://oss-cn-qingdao.aliyuncs.com', bucket_name)

    if path == '/':
        oldwar = old_version + '/' + war_name
        newar = new_version + '/' + war_name
    else:
        oldwar = path + '/' + old_version + '/' + war_name
        newar = path + '/' + new_version + '/' + war_name

    obj = [oldwar,newar]


    for i in obj:
        return_result = war_exist(i)
        if return_result == True:
示例#5
0
# -*- coding: utf-8 -*-
_author_ = 'chenchuchuan'

import oss2
import time
from random import randint
import StringIO, re, os
from config import Access_Key_ID, Access_Key_Secret, endpoint, bucket_name

auth = oss2.Auth(Access_Key_ID, Access_Key_Secret)
service = oss2.Service(auth, endpoint)

bucket = oss2.Bucket(auth, endpoint, bucket_name)


def upload_file_to_oss(from_file_url, upload_url):
    """上传文件到oss服务器"""
    success = False
    try:
        with open(from_file_url, 'rb') as fileobj:
            success = bucket.put_object(upload_url, fileobj)
    except Exception, e:
        pass
    return success


def upload_file_images_to_oss(file, upload_url):
    """上传文件到oss服务器(StringIO)"""
    success = False
    try:
        # bucket.put_object(upload_url, file.getvalue())
示例#6
0
 def __init__(self, accessKey, accessSecret):
     self.accessKey = accessKey
     self.accessSecret = accessSecret
     self.auth = oss2.Auth(self.accessKey, self.accessSecret)
     self.url = "http://oss-cn-hangzhou.aliyuncs.com"
     self.service = oss2.Service(self.auth, self.url)
示例#7
0
    def __init__(self, *argc, **argkw):
        config = ConfigParser.ConfigParser()
        config.readfp(open(AP + "config/config.ini"))
        COOKIE_SECRET = config.get("app", "COOKIE_SECRET")
        FACE_API_KEY = config.get("app", "FACE_API_KEY")
        FACE_API_SECRET = config.get("app","FACE_API_SECRET")
        ALIYUN_KEY = config.get("app","ALIYUN_KEY")
        ALIYUN_SECRET = config.get("app","ALIYUN_SECRET")
        template_path = os.path.join(AP + "templates")
        static_path = os.path.join(AP + "static")
        appid = config.get("YOUTU","APPID")
        secret_id = config.get("YOUTU","SECRET_ID")
        secret_key = config.get("YOUTU","SECRET_KEY")
        userid = config.get("YOUTU","USERID")
        logging.info("start server.")
        settings = dict(
            cookie_secret=COOKIE_SECRET,
            xsrf_cookies=False,
            template_path=template_path,
            static_path=static_path
        )

        handlers = [
            # test
            (r'/', IndexHandler),
            (r'/sleep',SleepHandler),
            (r'/user/register', RegisterHandler),
            (r'/user/login', LoginHandler),
            (r'/user/logout', LogoutHandler),
            (r'/user/confirm', ConfirmHandler),
            (r'/user/peronlistinfo',MyPersonListHandler),
            (r'/user/updatestatus', UpdateStatusHandler),
            (r'/find/searchperson', SearchPersonHandler),
            (r'/find/callhelp', CallHelpHandler),
            (r'/find/compare', ComparePersonHandler),
            (r'/get/updateperson',LastestUpdatePersonHandler),
            (r'/get/updatemessage',LastestUpdateMessageHandler),
            (r'/get/persondetail',GetMissingPersonDetailHandler),
            (r'/get/persondetail/web',GetMissingPersonDetailWebHandler),
            (r'/get/trackinfo/web',GetPersonTracksHandler),
            (r'/get/alltrack/web',GetAllTracksHandler),
            (r'/web/index',IndexPageHandler),
            (r'/web/details',DetailPageHandler),
            (r'/web/file',FilePageHandler),
            (r'/download',DownloadHandler),
            (r'/admin/import',ImportPersonHandler)
            
        ]

        tornado.web.Application.__init__(self, handlers, **settings)
        # use SQLachemy to connection to mysql.
        DB_CONNECT_STRING = 'mysql+mysqldb://%s:%s@%s/%s?charset=utf8'%(options.mysql_user, options.mysql_password, options.host, options.mysql_database)
        engine = create_engine(DB_CONNECT_STRING, echo=False,pool_size=1000)
        self.sqldb = sessionmaker(
                bind=engine,
                autocommit=False, 
                autoflush=True,
                expire_on_commit=False)
        base_model = declarative_base()
        # create all of model inherit from BaseModel 
        base_model.metadata.create_all(engine) 
        # use pymongo to connectino to mongodb
        logging.info("connect mongodb ..")
        client = pymongo.MongoClient(options.host,27017)
        client.cloudeye.authenticate(options.mongo_user,options.mongo_password)
        self.mongodb = client.cloudeye
        # bind face++ cloud service
        logging.info("connect mongodb successfully..")
        # self.facepp = API(FACE_API_KEY, FACE_API_SECRET)
        end_point = TencentYoutuyun.conf.API_YOUTU_END_POINT
        self.youtu = TencentYoutuyun.YouTu(appid, secret_id, secret_key, userid, end_point)
        # bind ali cloud service
        auth = oss2.Auth(ALIYUN_KEY,ALIYUN_SECRET)
        endpoint = r'http://oss-cn-shanghai.aliyuncs.com'
        bucket_name = 'cloudeye'
        self.ali_service = oss2.Service(auth, endpoint)
        self.ali_bucket = oss2.Bucket(auth, endpoint, bucket_name)
        # bind redis service
        logging.info("connect redis..")
        self.redis = redis.Redis(host='localhost',port=6379)
        logging.info("connect redis successfully..")
        if options.flush_redis==1:
            self.redis.flushall()
        logging.info("start completed..")
示例#8
0
 def __init__(self, conf):
     self.conf = conf
     # Due to a bug in httplib we can't use https
     self.auth = oss2.Auth(conf.key_id, conf.key)
     self.service = oss2.Service(self.auth, conf.host)
     self.bucket = oss2.Bucket(self.auth, conf.host, conf.bucket_name)
示例#9
0
 def bucket_list(self, auth):
     service = oss2.Service(auth, "oss.hangzhou.com")
     print([b.name for b in oss2.BucketIterator(service)])
示例#10
0
 def test_bucket_iterator(self):
     service = oss2.Service(oss2.Auth(OSS_ID, OSS_SECRET), OSS_ENDPOINT)
     self.assertTrue(OSS_BUCKET in (b.name for b in oss2.BucketIterator(service, max_keys=2)))
示例#11
0
# @Author  : Tony Wang
import datetime
import json
import os
import random

import requests
import time
import tornado as tornado
import tornado.ioloop
import tornado.web
import core
import oss2
# 配置OSS
auth = oss2.Auth('你的阿里云AccessKeyId', '你的阿里云AccessKeySecret')
service = oss2.Service(auth, 'oss-cn-shenzhen.aliyuncs.com')


# 上传图片文件到OSS上,返回网络路径,上传完之后删除本地的文件
def uploadFileToOSS(output_file):
    bucket = oss2.Bucket(auth, 'http://oss-cn-shenzhen.aliyuncs.com',
                         'ltian-2017')
    filePath = 'https://ltian-2017.oss-cn-shenzhen.aliyuncs.com/'
    fileName = 'timecamera/result_image/' + datetime.datetime.now().strftime(
        '%Y%m%d_%H%M%S') + '_' + str(random.randint(0, 9)) + '.png'
    bucket.put_object_from_file(fileName, output_file)
    if os.path.exists(output_file):
        # 删除文件
        os.remove(output_file)
    return filePath + fileName
示例#12
0
 def __init__(self):
     auth = oss2.Auth('xxx', 'xxx')
     service = oss2.Service(auth, 'xxx')
     self._bucket = oss2.Bucket(auth, 'xxx', 'xxx')
     pass
示例#13
0
 def bucket_list(self):
     # 查看bucket 列表
     service = oss2.Service(self.auth,
                            'http://oss-cn-hangzhou.aliyuncs.com')
     print([b.name for b in oss2.BucketIterator(service)])
示例#14
0
# -*- coding: utf-8 -*-
import oss2

try:
    auth = oss2.Auth('LTAI7gb42H0riIA7', 'qMvzhm7QQnwlZ7wgKCDxTvSpK2meC6i')
    #auth = oss2.Auth('LTAI7gb42H0riIA7', 'qMvzhm7QQnwlZ7wgKCDxTvSpK2meC5')
except Exception, err:
    print err

#bucket = oss2.Bucket(auth, 'http://oss-cn-hangzhou.aliyuncs.com', 'wang-zhen')
service = oss2.Service(auth, 'http://oss-cn-beijing.aliyuncs.com')

#bucket.create_bucket()
res = service.list_buckets()
for bk in res.buckets:
    print bk.name
    print bk.creation_date
    print bk.location
    print bk.extranet_endpoint
#print([b.name for b in oss2.BucketIterator(service)])
#print bucket
示例#15
0
 def __init__(self, accesskey_id=None, secret=None, endpoint=None, bucket_name=None):
     auth = oss2.Auth(accesskey_id, secret)
     # 设置超时时间
     oss2.Service(auth, endpoint, connect_timeout=30)
     self.bucket = oss2.Bucket(auth, endpoint, bucket_name)