zoukankan      html  css  js  c++  java
  • 分片上传

    [root@myv ~]# python /data/xiaole_dl_img/myossupload.py
    Traceback (most recent call last):
      File "/data/xiaole_dl_img/myossupload.py", line 62, in <module>
        res = bucket.put_object(s, fr.read())
    MemoryError
    [root@myv ~]# free -g
                 total       used       free     shared    buffers     cached
    Mem:            31         30          0          0          0          4
    -/+ buffers/cache:         26          4
    Swap:            0          0          0
    [root@myv ~]# top

    上传文件_Python-SDK_SDK 参考_对象存储 OSS-阿里云  https://help.aliyun.com/document_detail/32030.html

        i = '/data/xiaole_dl_img/dlDBimg/mybanner.zip'
        with open(i, 'rb') as fr:
            auth = oss2.Auth(kid, ks)
            bucket = oss2.Bucket(auth, ep, bn)
            s = '{}{}'.format('testtmp/', 'mybanner.zip')
            res = bucket.put_object(s, fr.read())
    

      

    <oss2.models.PutObjectResult object at 0x7f1d01c7ac18>
    2038
    <oss2.models.PutObjectResult object at 0x7f1d01c7afd0>
    2039
    <oss2.models.PutObjectResult object at 0x7f1d01c6f6d8>
    2040
    <oss2.models.PutObjectResult object at 0x7f1d01c77438>
    2041
    <oss2.models.PutObjectResult object at 0x7f1d01c77908>
    2042
    <oss2.models.PutObjectResult object at 0x7f1d01c79f98>
    2043
    <oss2.models.PutObjectResult object at 0x7f1d01c79748>
    2044
    <oss2.models.PutObjectResult object at 0x7f1d01c6fcc0>
    2045
    <oss2.models.PutObjectResult object at 0x7f1d01c79da0>
    2046
    <oss2.models.PutObjectResult object at 0x7f1d01c79278>
    2047
    <oss2.models.PutObjectResult object at 0x7f1d01c6f940>
    2048
    <oss2.models.PutObjectResult object at 0x7f1d01c6fcc0>
    2049
    <oss2.models.PutObjectResult object at 0x7f1d01c79048>
    2050
    <oss2.models.PutObjectResult object at 0x7f1d01c6f4a8>
    2051
    <oss2.models.PutObjectResult object at 0x7f1d01c6fa90>
    2052
    <oss2.models.PutObjectResult object at 0x7f1d01c6fef0>
    2053
    <oss2.models.PutObjectResult object at 0x7f1d01c6f860>
    2054
    <oss2.models.PutObjectResult object at 0x7f1d01c77cc0>
    2055
    <oss2.models.PutObjectResult object at 0x7f1d01c77f98>
    2056
    <oss2.models.PutObjectResult object at 0x7f1d01c77748>
    2057
    <oss2.models.PutObjectResult object at 0x7f1d01c779e8>
    2058
    <oss2.models.PutObjectResult object at 0x7f1d01c79048>
    2059
    <oss2.models.PutObjectResult object at 0x7f1d01c79a20>
    2060
    

      

      i = '/data/xiaole_dl_img/dlDBimg/mybanner.zip'
        # with open(i, 'rb') as fr:
        #     auth = oss2.Auth(kid, ks)
        #     bucket = oss2.Bucket(auth, ep, bn)
        #     s = '{}{}'.format('testtmp/', 'mybanner.zip')
        # res = bucket.put_object(s, fr.read())
        auth = oss2.Auth(kid, ks)
        bucket = oss2.Bucket(auth, ep, bn)
        s = '{}{}'.format('testtmp/', 'mybanner.zip')
        key = s
        filename = i
        total_size = os.path.getsize(filename)
        part_size = determine_part_size(total_size, preferred_size=100 * 1024)
        # 初始化分片
        upload_id = bucket.init_multipart_upload(key).upload_id
        parts = []
        # 逐个上传分片
        with open(filename, 'rb') as fileobj:
            part_number = 1
            offset = 0
            while offset < total_size:
                num_to_upload = min(part_size, total_size - offset)
                result = bucket.upload_part(key, upload_id, part_number,
                                            SizedFileAdapter(fileobj, num_to_upload))
                parts.append(PartInfo(part_number, result.etag))
                offset += num_to_upload
                part_number += 1
                print(result)
                print(part_number)
        # 完成分片上传
        bucket.complete_multipart_upload(key, upload_id, parts)
        # 验证一下
        with open(filename, 'rb') as fileobj:
            assert bucket.get_object(key).read() == fileobj.read()
    

      

  • 相关阅读:
    Linux基础--安装搭建tomcat+java+mysql
    使用ArcGIS JavaScript API 3.18 加载天地图
    关于ArcGIS的Web 3D GIS问答
    ArcGIS 10.5新功能预览
    如何选择合适分辨率的遥感影像
    如何正确响应ArcGIS JavaScript API中图形的鼠标事件
    安装Portal for ArcGIS时如何正确配置HTTPS证书
    ArcGIS地图文档优化 mxdPerfstat工具使用体验
    Web AppBuilder Widget使用共享类库的方式
    如何通过ArcMap Add-in机制实现十字叉线地理配准工具
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9004622.html
Copyright © 2011-2022 走看看