You need to enable JavaScript to run this app.
导航
内网上传
最近更新时间:2025.04.01 15:09:26首次发布时间:2025.04.01 15:09:26
我的收藏
有用
有用
无用
无用

阅读本文,您可以获取 Python SDK 内网上传资源的接口调用示例,实现快速开发。

调用说明

本文提供的接口调用示例均通过 AK 和 SK 初始化实例。

前提条件

调用接口前,请先完成 Python SDK 的安装及初始化操作。

注意事项

若服务内已经存在同名文件,且您开启了重名覆盖上传,则新上传文件在上传路径及文件名重复时将覆盖同名旧文件。若未开启重名覆盖上传,则新文件上传失败。

调用示例

本节为您介绍内网上传的调用示例。该示例内部依次调用封装了 ApplyVpcUploadInfoCommitImageUpload 接口以及上传逻辑,从而实现完整的文件上传流程。

# coding:utf-8
from __future__ import print_function
from volcengine.imagex.v2.imagex_service import ImagexService

if __name__ == '__main__':
    imagex_service = ImagexService()

    # call below method if you dont set ak and sk in $HOME/.volc/config
    imagex_service.set_ak('ak')
    imagex_service.set_sk('sk')

    request = dict()
    request["ServiceId"] = "service id"      # 服务 ID
    request["FilePath"] = "your file path"   # 文件路径,与Data二选一
    request["Data"] = 'your data'            # 文件二进制数据,与FilePath二选一
    request["StoreKey"] = "your store key"   # 文件存储名
    request["Prefix"] = "your prefix"        # 文件前缀
    request["FileExtension"] = "your file extension"    # 文件后缀
    request["ContentType"] = "your content type"    # 文件Content-Type
    request["StorageClass"] = "your storage class"  # 文件存储类型
    request["PartSize"] = 0                         # 偏好分片大小,单位为字节(0表示按照默认规则分片)
    request["Overwrite"] = False                    # 是否覆盖已有文件
    request["SkipMeta"] = False                     # 是否跳过元信息
    try:
        resp = imagex_service.vpc_upload_image(request)
        print(resp)
    except Exception as e:
        print(e)