Package: tornado_qiniu
Installation$python3.xsetup.pyinstallor$pip3.xinstalltornado_qiniuEnvironmenttornado_qiniu versionpython version1.03.4,3.5Quick StartResource Upload and Downloadfromtornadoimportgen,ioloopfromtornado_qiniuimportQiniuClientaccess_key="your qiniu access key"secret_key="your qiniu secret key"bucket_name="your bucket name"domain="your domain"bucket_acp=0#bucket access property,1 ===>private bucket,0===>public bucketclient=QiniuClient(access_key,secret_key,domain)loop=ioloop.IOLoop.current()#get a bucket instancebucket=client.bucket(bucket_name,bucket_acp=1)#get bucket upload tokenbucket.upload_token()# get resource urlbucket.res("resource_key").url()bucket.res('key1','key2').url()# download resource@gen.coroutinedefget_resource():response=yieldbucket.res("resource_key").get()#return   saved name# get multi resourceresponse=yieldbucket.res('key1','key2').get()#return a list of the  saved  nameloop.run_sync(get_resource)# upload resource@gen.coroutinedefupload():#when file's size greater than 4MB,using shard uploading#after uploading successfully,return key name and file hash valueresponse=yieldbucket.res("key").put("./testfile")#return resource hash value,and keyloop.run_sync(upload)loop.close()Resource Managementfromtornadoimportgen,ioloopfromtornado_qiniuimportQiniuClientaccess_key="your qiniu access key"secret_key="your qiniu secret key"bucket_name="your bucket name"domain="your domain"bucket_acp=0#bucket access property,1 ===>private bucket,0===>public bucketclient=QiniuClient(access_key,secret_key,domain)bucket=client.bucket(bucket_name,bucket_acp=bucket_acp)loop=ioloop.IOLoop.current()#single resource management@gen.coroutinedefsingle_resource_manage():#resource statestate=yieldbucket.res('key').stat()#resource deletingyieldbucket.res('key').delete()#resource movingyieldbucket.res('src_key').moveto('dest_key','dest_bucket')#resource copingyieldbucket.res('src_key').copyto('dest_key','dest_bucket')loop.run_sync(single_resource_manage)#multi resource management@gen.coroutinedefmulti_resource_manage():#multi resource statestate=yieldbucket.res('key1','key2','key3').multi_stat()#multi resource deletingyieldbucket.res('key1','key2','key3').multi_delete()#multi resource copingyieldbucket.res(*['key1','key2']).multi_copyto(['dest_key1','dest_key2'],'dest_bucket')#multi resource movingyieldbucket.res('key1','key2').multi_moveto(['dest_key1','dest_key2'],'dest_bucket')loop.run_sync(multi_resource_manage)# resource management batch operation@gen.coroutinedefbatch_ops():#get batch instancebatch=bucket.res().batch()batch.stat('keyname1')batch.delete('keyname2')#execute batchyieldbatch.execute()#multi resource batch operationbatch=bucket.res('key1','key2').batch()batch.multi_stat()batch.multi_copy(['dest_key1','dest_key2'],'dest_bucket')batch.multi_move(['dest_key1','dest_key2'],'dest_bucket')#list all resources in current bucketbatch.list()#execute batch ,return json format datayieldbacth.execute()loop.run_sync(batch_ops)Resource Processfromtornadoimportgen,ioloopfromtornado_qiniuimportQiniuClientaccess_key="your qiniu access key"secret_key="your qiniu secret key"bucket_name="your bucket name"domain="your domain"bucket_acp=0#bucket access property,1 ===>private bucket,0===>public bucketclient=QiniuClient(access_key,secret_key,domain)bucket=client.bucket(bucket_name,bucket_acp=bucket_acp)loop=ioloop.IOLoop.current()# get resource info@gen.coroutinedefget_info():# get image infoimginfo=yieldbucket.res("dummy_img_key").imageinfo().get()# get image aveimgave=yieldbucket.res("dummy_img_key").imageave().get()# get image exifimgexif=yieldbucket.res("dummy_img_key").imageexif().get()loop.run_sync(get_info)# resource fops@gen.coroutinedefresource_fops():# resource qrcode urlqrcodeurl=bucket.res("dummy_img_key").fops().qrcode().url()# get resource qrcode imgqrcodeimg=yieldbucket.res("dummy_img_key").fops().qrcode().get()# resource text_watermarktext_watermark_url=bucket.res("dummy_img_key").fops().text_watermark("dummy").url()text_watermark_img=yieldbucket.res("dummy_img_key").fops().text_watermark("dummy").get()#  resource image watermarkimg_url=bucket.res("water_img").url()watered_img_url=bucket.res("dummy_img_key").fops().image_watermark(img_url).url()waterd_img=yieldbucket.res("dummy_img_key").fops().image_watermark(img_url).get()# resource fops saveassaveas_url=bucket.res("dummy_key").fops().text_watermark("dummy").saveas("dummy_watermark").url()yieldbucket.res("dummy_key").fops().text_watermark("dummy").saveas("dummy_watermark").get()# resource fops persistent# audio/vedio slice operation, the detail args refer to:# http://developer.qiniu.com/code/v6/api/dora-api/av/segtime.htmlyieldbucket.res("dummy_av").fops().avthumb_slice(no_domain=1).persistent()# audio/vedio transcoding operation,the detail args refer to:# http://developer.qiniu.com/code/v6/api/dora-api/av/avthumb.htmlyieldbucket.res("dummy_av").fops().avthumb_transcoding("mp3").persistent()# audio/vedio concat operation,the detail args refer to :# http://developer.qiniu.com/code/v6/api/dora-api/av/avconcat.htmlyieldbucket.res("dummy_av").fops().avconcat(mode=2,frmt="mp4",url1="http://**",url2="http://**").persistent()# audio/vedio vframe operation ,the detail args refer to:# http://developer.qiniu.com/code/v6/api/dora-api/av/vframe.htmlyieldbucket.res("dummy_av").fops().vframe("jpg",200,w=1000,h=3030).persistent()# get audio/vedio informationavinfo=yieldbucket.res("dummy_av").avinfo().get()avinfo_url=bucket.res("dummy_av").avinfo().url()# prefop interfaceresponse=yieldbucket.res("key1").prefop("persistent_id")LicenseMIT License