Simple cos File upload test

Source: Internet
Author: User
Tags cos

I. BACKGROUND

Customer feedback randomly upload small files to the Cos speed is slow, using Python to test upload speed.

Second, the Code
#!/bin/env python#-*-coding:utf-8-*-# _auth:kaliarch# use cos-python-sdk-v5# https://cloud.tencent.com/document/ Product/436/12269from qcloud_cos Import cosconfigfrom qcloud_cos import coss3clientimport randomimport stringimport datetimesecret_id = ' Akidmdjegcmogyiolxxxxxxxxxxxxxxxxde ' # replaced with the user's Secretidsecret_key = ' d5mrl4voxyxxxxxxxxxxxa2lnq7d ' # replaced with the user's secretkeyregion = ' Ap-chengdu ' # replaced with the user's region # Use temporary key to pass in Token, default is empty, can not fill scheme = ' HT TPS ' # Specifies to use the HTTP/HTTPS protocol to access the COS, which is https by default, Bucket_name = ' xuel-test-bucket-1253961596 ' #制定bucket地址con Fig = Cosconfig (region=region, secret_id=secret_id, Secret_key=secret_key, Scheme=scheme) # 2.    Get Client Object clients = Coss3client (config) def get_data_list (number): "" "gets a random string, numbers specifies the quantity:p Aram #:: Return:         "" For I in range (int (number)): Random_str = '. Join (Random.sample (string.ascii_letters + string.digits, 12)) Yield Str (i) + random_strdef Get_func_time (func): "" "    Adorner function:p aram func: Calculate inner function Execution time: return: "" "Def Inter_func (*args): Stime = Datetime.datetime.now () Print (' Start datetime: ', Stime) func (*args) etime = Datetime.datetime.now () print (' Start Dateti    Me: ', etime) print (' Duration time ', etime-stime) return inter_func@get_func_timedef Upload_cos (number=1000): "" "Cos file upload:p Aram Number:: Return:" "" Print (' data file Number: ', str (number)) for content in Get_dat A_list (number): Response = Client.put_object (Bucket=bucket_name, Body=bytes (content,encoding = ' Utf-8 '), key=content,) if __name__ = = ' __main__ ': Upload_cos (1000)
Third, testing

Test 500 random files

Test 1000 random files

View Cos file data

Simple cos File upload test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.