参考php版本的源代码http://apidoc.sinaapp.com/__filesource/fsource_sae__saestorage.class.php.html ,扩展读取目录,按目录读取文件,分页读取文件等功能。

REST操作地址:#define( 'SAE_STOREHOST', 'http://stor.sae.sina.com.cn/storageApi.php' );

这个地址是从php版本的库中找的,python库的源代码还看不到。

post上传文件插件:

https://github.com/seisen/urllib2_file

经验证使用urllib2_file插件上传文件没问题,使用代码如下:

postData = {'destfile':destFileName, 'srcFile':{'fd':srcFile.file, 'filename': destFileName}}
 
def openUrl(self, urlStr, postData = {}, decode = True):
        import urllib
        import urllib2
        try:
            if postData:
                import urllib2_file
                opener = urllib2.build_opener(urllib2_file.newHTTPHandler)
                urllib2.install_opener(opener)
                request = urllib2.Request(urlStr, postData)
                #response =opener.open(urlStr, postData)
            else:
                values = {}
                data = urllib.urlencode(values)
                headers = { 'User-Agent' : 'SAE Online Platform' }
                request = urllib2.Request(urlStr, data, headers)
            response = urllib2.urlopen(request)
            content = response.read()
            import json
            retJson = json.loads(content)
        except Exception, ex:
            retJson = {'data':'ERROR:%s'%(str(ex.args))}
        #打印日志
        if settings.LOG:
            print 'SinaCloudStorage-urlStr:%s;retJson:%s' % (urlStr, str(retJson), )
        return retJson


http://alexliyu.blog.163.com/blog/static/162754496201252154412432/

http://pipe.scs.fsu.edu/PostHandler/MultipartPostHandler.py

storage服务端返回的rest内容格式

SinaCloudStorage-
urlStr:
http://stor.sae.sina.com.cn/storageApi.php?act=getfileslist&ak=ak&sk=sk&dom=dom-pic&path=&limit=10&skip=0&fold=1;
retJson:{
u'errno': 0, 
u'data': {
u'dirs': [{u'fullName': u'test/', u'name': u'test'}, {u'fullName': u'test2/', u'name': u'test2'}], 
u'dirNum': 2, 
u'fileNum': 5, 
u'files': [
{u'uploadTime': 1347376869, u'length': 16093, u'fullName': u'01.png', u'Name': u'01.png'}, 
{u'uploadTime': 1348038280, u'length': 104458, u'fullName': u'1-110222151918.jpg', u'Name': u'1-110222151918.jpg'}, 
{u'uploadTime': 1348038248, u'length': 121605, u'fullName': u'1-110222151921.jpg', u'Name': u'1-110222151921.jpg'}, 
{u'uploadTime': 1348038288, u'length': 63013, u'fullName': u'1-110222151922.jpg', u'Name': u'1-110222151922.jpg'}, 
{u'uploadTime': 1347810039, u'length': 25676, u'fullName': u'2.png', u'Name': u'2.png'}]}, 
u'errmsg': u'success'
}

经验证这个方法可行,随后公布给大家使用