七牛python sdk保存文件到七牛云存储,无法处理数据中尖括号
高洛峰
高洛峰 2017-04-17 13:26:01
0
1
526

比如下面这样的数据

    <!doctype html>
    <html xmlns:ng="http://angularjs.org">
        <body>
            Hello {{'World'}}!
            <script src="http://code.angularjs.org/angular.js"></script>
            <script>
                angular.element(document).ready(function() {
                angular.bootstrap(document);
                });
            </script>
        </body>
    </html>

我想通过StringIO的方式保存到七牛云存储,得到不同的结果

  • 如果是通过文件上传的,存储过程正常
  • 如果是通过post方式在字段中提交的,存储过程失败,返回的错误信息为limited mimeType: ExpUser can only upload image/audio/video/plaintext, reqid:vxUAAPAePxkbbJQT,但是hard code去掉尖括号,就正常了

实现的代码参考了七牛python sdk的文档

policy = qiniu.rs.PutPolicy(bucket_name)
uptoken = policy.token()

extra = qiniu.io.PutExtra()
extra.mime_type = "text/plain"
extra.params = {'x:a': 'a'}

data = u"""
## 概览
    <!doctype html>
    <html xmlns:ng="http://angularjs.org">
        <body>
            Hello {{'World'}}!
            <script src="http://code.angularjs.org/angular.js"></script>
            <script>
                angular.element(document).ready(function() {
                angular.bootstrap(document);
                });
            </script>
        </body>
    </html>

下面是一些你的代码必须遵守的顺序:

1. 等页面和所有的脚本加载完之后,找到HTML模板的根节点——通常就是文档的根节点。
2. 调用 api/angular.bootstrap将模板编译成可执行的、数据双向绑定的应用程序。

<span class="doc-copyright">**版权声明:** **中文文档[AngularJS中文社区][]** && **英文文档[AngularJS官网][]** && **代码许可[The MIT License][]** && **文档许可[CC BY 3.0][]**</span>"
"""

data = data.strip().encode('utf-8')
data = str(data)

strio = StringIO.StringIO()
strio.write(data)


result, error = qiniu.io.put(uptoken, 'xxx', strio, extra)
print error

不知道怎么解决...请教

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
阿神

Reporting this errorlimited mimeType: ExpUser can only upload image/audio/video/plaintext means that you are an experience user. Qiniu Service has more content and determines that the field you uploaded is not plaintext, but an html file (experience users cannot upload html files), causing the upload to fail. , so it is recommended that you become a standard user through the following identity authentication, so that you can avoid masking.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template