Esempio n. 1
0
 def putdata(self, data):
     """
     把文件推送到bcs
     by:王健 at:2015-1-28
     把文件推送到七牛
     by: 范俊伟 at:2015-04-14
     :param data:
     :return:
     """
     key = self.fileurl
     token = qn_auth.upload_token(self.bucket, expires=3600 * 24)
     ret, info = uploader.put_data(token, key, data, check_crc=True)
     return ret['key'] == key
Esempio n. 2
0
 def putdata(self, data):
     """
     把文件推送到bcs
     by:王健 at:2015-1-28
     把文件推送到七牛
     by: 范俊伟 at:2015-04-14
     :param data:
     :return:
     """
     key = self.fileurl
     token = qn_auth.upload_token(self.bucket, expires=3600 * 24)
     ret, info = uploader.put_data(token, key, data, check_crc=True)
     return ret['key'] == key
Esempio n. 3
0
#!/usr/bin/python
Esempio n. 4
0
def bcs_pic_to_qiniu():
    """
    把bcs图片弄到七牛上面
    by:尚宗凯 at:2015-06-03
    修改为数据流上传
    by:尚宗凯 at:2015-06-03
    优化bucket
    by:尚宗凯 at:2015-06-03
    """
    bf = BaseFile.objects.all()
    for i in bf:
        if i.bucket in ("projectfiles", "pubfriendsicon", "pubproject"):
            # if i.bucket in ("qn-projectfiles"):
            url = i.get_url()
            if url.startswith("http://bcs.duapp.com/"):
                #下载
                # print url
                try:
                    conn = urllib2.urlopen(url)
                    # localfile = ""
                    # tmp = i.fileurl.strip().split("/")
                    # if len(tmp) == 3:
                    #     project_id = tmp[1]
                    #     pic_name = tmp[2]
                    # localfile = save_path+project_id+"_"+pic_name
                    # localfile = project_id+"_"+pic_name

                    # conn.read()
                    # f = open(localfile,'wb')
                    # f.write(conn.read())
                    # f.close()

                    #上传
                    # data = conn.read()
                    qn_auth = qiniu.Auth(QN_AK, QN_SK)
                    if i.bucket == 'projectfiles':
                        bucket = 'qn-projectfiles'
                    elif i.bucket == 'pubfriendsicon':
                        bucket = 'qn-pubfriendsicon'
                    elif i.bucket == 'pubproject':
                        bucket = 'qn-pubproject'
                    token = qn_auth.upload_token(bucket, expires=3600 * 24)
                    key = i.fileurl
                    ret, info = uploader.put_data(
                        token,
                        key,
                        conn.read(),
                        mime_type="application/octet-stream",
                        check_crc=True)
                    if info.status_code == 614:
                        pass
                    else:
                        assert ret['key'] == key
                        i.bucket = bucket
                        i.save()
                        # 验证文件是否能打开
                        if bucket == 'qn-projectfiles':
                            base_url = QN_FILE_BUCKET_DOMAIN + key
                        elif bucket == 'pubfriendsicon':
                            base_url = QN_FRIENDS_ICON_BUCKET_DOMAIN + key
                        elif i.bucket == 'pubproject':
                            base_url = QN_PROJECT_ICON_BUCKET_DOMAIN + key
                        private_url = qn_auth.private_download_url(
                            base_url, expires=3600)
                        print "private_url:", private_url
                except Exception as e:
                    print e
Esempio n. 5
0
def bcs_pic_to_qiniu():
    """
    把bcs图片弄到七牛上面
    by:尚宗凯 at:2015-06-03
    修改为数据流上传
    by:尚宗凯 at:2015-06-03
    优化bucket
    by:尚宗凯 at:2015-06-03
    """
    bf = BaseFile.objects.all()
    for i in bf:
        if i.bucket in ("projectfiles","pubfriendsicon","pubproject"):
        # if i.bucket in ("qn-projectfiles"):
            url = i.get_url()
            if url.startswith("http://bcs.duapp.com/"):
                #下载
                # print url
                try:
                    conn = urllib2.urlopen(url)
                    # localfile = ""
                    # tmp = i.fileurl.strip().split("/")
                    # if len(tmp) == 3:
                    #     project_id = tmp[1]
                    #     pic_name = tmp[2]
                        # localfile = save_path+project_id+"_"+pic_name
                        # localfile = project_id+"_"+pic_name

                        # conn.read()
                        # f = open(localfile,'wb')
                        # f.write(conn.read())
                        # f.close()

                    #上传
                    # data = conn.read()
                    qn_auth = qiniu.Auth(QN_AK, QN_SK)
                    if i.bucket == 'projectfiles':
                        bucket = 'qn-projectfiles'
                    elif i.bucket == 'pubfriendsicon':
                        bucket = 'qn-pubfriendsicon'
                    elif i.bucket == 'pubproject':
                        bucket = 'qn-pubproject'
                    token = qn_auth.upload_token(bucket, expires=3600 * 24)
                    key = i.fileurl
                    ret, info = uploader.put_data(token, key, conn.read(), mime_type="application/octet-stream", check_crc=True)
                    if info.status_code == 614:
                        pass
                    else:
                        assert ret['key'] == key
                        i.bucket = bucket
                        i.save()
                        # 验证文件是否能打开
                        if bucket == 'qn-projectfiles':
                            base_url = QN_FILE_BUCKET_DOMAIN + key
                        elif bucket == 'pubfriendsicon':
                            base_url = QN_FRIENDS_ICON_BUCKET_DOMAIN + key
                        elif i.bucket == 'pubproject':
                            base_url = QN_PROJECT_ICON_BUCKET_DOMAIN + key
                        private_url = qn_auth.private_download_url(base_url, expires=3600)
                        print "private_url:",private_url
                except Exception as e:
                    print e