OSS — 阿里云提供的一种存储服务

模块

使用示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# coding=utf-8
# This is a sample Python script.
import OSS
print("-------------------Welcome OSS MicroPython--------------------")

print("-----OSS demo start-----")
OSS_ACCESS_KEY = "xxxx"
OSS_ACCESS_SECRET = "xxxx"
OSS_ENDPOINT = "xxxx"
OSS_BUCKET = "xxxx"
File_PATH = "/data/python-apps/oss/res/test.jpg"
File_CONTENT = "oss test content"

urlFile = OSS.uploadFile(OSS_ACCESS_KEY, OSS_ACCESS_SECRET, OSS_ENDPOINT, OSS_BUCKET, File_PATH)
print("File url:")
print(urlFile)
urlContent = OSS.uploadContent(OSS_ACCESS_KEY, OSS_ACCESS_SECRET, OSS_ENDPOINT, OSS_BUCKET, File_CONTENT)
print("Content url:")
print(urlContent)

print("-----OSS demo end-----")

函数接口


oss.uploadFile(key, secret, endPoint, bucketName, filePath)[源代码]

上传资源文件

参数
  • key – “Your-Access-Key”

  • secret – “Your-Access-Secret”

  • endPoint – “Your-OSS-Endpoint”

  • bucketName – “Your-OSS-Bucket”

  • filePath – “文件路径”

返回

!0: 传成功后对应的url,0: 失败

引发

OSError – EINVAL

oss.uploadContent(key, secret, endPoint, bucketName, fileContent)[源代码]

上传资源文件内容

参数
  • key – “Your-Access-Key”

  • secret – “Your-Access-Secret”

  • endPoint – “Your-OSS-Endpoint”

  • bucketName – “Your-OSS-Bucket”

  • fileContent – “文件内容”

返回

!=0: 传成功后对应的url,0: 失败

引发

OSError – EINVAL