全部产品
云市场

基于OSS原生SDK上传视频到点播

更新时间:2019-08-13 17:18:51

场景

视频点播提供了丰富的 上传方式,包括 客户端上传服务端上传 等,但可能缺乏需要的语言版本(如Go等),此时,可以直接基于OSS原生SDK进行上传。

前提

在阅读本文前,请先确定确实没有您所需要语言版本的上传SDK,点播服务已提供:

也可以直接访问 SDK下载页面 下载SDK和Demo;如确实没有您需要的版本,可以继续阅读本文再行开发。

准备工作

  • 确认已开通点播服务并完成了相关配置。
  • 确认已准备了 阿里云账号AccessKey,并授予了上传权限。

上传步骤

上传流程.png

1. 访问点播服务获取上传地址和上传凭证

这一步还会创建视频媒资记录,返回视频ID,请妥善保存,后续可根据视频ID进行视频播放、管理和AI处理等。

2. 解析上传地址(UploadAddress) 和 上传凭证(UploadAuth),得到OSS的上传地址和授权信息。解析方式参考 上传地址和凭证的解析

3. 调用OSS SDK将视频文件上传至指定的bucket中,注意使用STS Auth方式,且使用解析后的上传地址和授权信息进行初始化,不要使用自己的AccessKey等信息。

代码实现

PHP上传示例

环境准备

  • PHP 5.3+,可通过php -v命令查看当前的PHP版本。
  • cURL 扩展,可通过php -m命令查看curl扩展是否已经安装好。

安装

  1. 在您的PHP项目中添加空文件夹 aliyun-php-sdk

  2. aliyun-openapi-php-sdk 下载整个源码,解压后拷贝 aliyun-php-sdk-corealiyun-php-sdk-vod 两个文件夹到 aliyun-php-sdk 目录下。

  3. aliyun-oss-php-sdk 下载最新的OSS PHP SDK的源码,解压ZIP文件后添加文件夹到 aliyun-php-sdk 目录下。以下载 v.2.2.4 Source code (zip) 为例,解压后文件夹为 aliyun-oss-php-sdk-2.2.4

  4. 打开 aliyun-php-sdk/aliyun-php-sdk-core/Config.php 文件,找到“//config sdk auto load path.”,在这行下面添加:

    1. Autoloader::addAutoloadPath("aliyun-php-sdk-vod");
  5. 在代码中引用VOD和OSS的文件:

  1. require_once './aliyun-php-sdk/aliyun-php-sdk-core/Config.php'; // 假定您的源码文件和aliyun-php-sdk处于同一目录。
  2. require_once './aliyun-php-sdk/aliyun-oss-php-sdk-2.2.4/autoload.php';
  3. use vod\Request\V20170321 as vod;
  4. use OSS\OssClient;
  5. use OSS\Core\OssException;

更多信息可参考VOD PHP SDK安装OSS PHP SDK安装

参考代码

  • 定义核心步骤的函数:

1. 使用AK初始化VOD客户端

  1. function init_vod_client($accessKeyId, $accessKeySecret) {
  2. $regionId = 'cn-shanghai'; // 点播服务所在的Region,国内请填cn-shanghai,不要填写别的区域
  3. $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
  4. return new DefaultAcsClient($profile);
  5. }

2. 获取视频上传地址和凭证

  1. function create_upload_video($vodClient) {
  2. $request = new vod\CreateUploadVideoRequest();
  3. $request->setTitle("视频标题"); // 视频标题(必填参数)
  4. $request->setFileName("文件名称.mov"); // 视频源文件名称,必须包含扩展名(必填参数)
  5. $request->setDescription("视频描述"); // 视频源文件描述(可选)
  6. $request->setCoverURL("http://img.alicdn.com/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png"); // 自定义视频封面(可选)
  7. $request->setTags("标签1,标签2"); // 视频标签,多个用逗号分隔(可选)
  8. return $vodClient->getAcsResponse($request);
  9. }

3. 使用上传凭证和地址初始化OSS客户端(注意需要先Base64解码并Json Decode再传入)

  1. function init_oss_client($uploadAuth, $uploadAddress) {
  2. $ossClient = new OssClient($uploadAuth['AccessKeyId'], $uploadAuth['AccessKeySecret'], $uploadAddress['Endpoint'],
  3. false, $uploadAuth['SecurityToken']);
  4. $ossClient->setTimeout(86400*7); // 设置请求超时时间,单位秒,默认是5184000秒, 建议不要设置太小,如果上传文件很大,消耗的时间会比较长
  5. $ossClient->setConnectTimeout(10); // 设置连接超时时间,单位秒,默认是10秒
  6. return $ossClient;
  7. }

注: 如果由于SSL配置异常导致错误(如出现cURL error: SSL certificate problem), 可将https替换为http后再初始化OssClient

  1. $uploadAddress['Endpoint'] = str_replace("https:", "http:", $uploadAddress['Endpoint']);

4. 上传本地文件

  1. function upload_local_file($ossClient, $uploadAddress, $localFile) {
  2. return $ossClient->uploadFile($uploadAddress['Bucket'], $uploadAddress['FileName'], $localFile);
  3. }

5. 刷新上传凭证

  1. function refresh_upload_video($vodClient, $videoId) {
  2. $request = new vod\RefreshUploadVideoRequest();
  3. $request->setVideoId($videoId);
  4. return $vodClient->getAcsResponse($request);
  5. }
  • 执行完整流程(注意捕获异常):
  1. $accessKeyId = '<AccessKeyId>'; // 您的AccessKeyId
  2. $accessKeySecret = '<AccessKeySecret>'; // 您的AccessKeySecret
  3. $localFile = '/Users/yours/Video/testVideo.flv'; // 需要上传到VOD的本地视频文件的完整路径
  4. try {
  5. // 初始化VOD客户端并获取上传地址和凭证
  6. $vodClient = init_vod_client($accessKeyId, $accessKeySecret);
  7. $createRes = create_upload_video($vodClient);
  8. // 执行成功会返回VideoId、UploadAddress和UploadAuth
  9. $videoId = $createRes->VideoId;
  10. $uploadAddress = json_decode(base64_decode($createRes->UploadAddress), true);
  11. $uploadAuth = json_decode(base64_decode($createRes->UploadAuth), true);
  12. // 使用UploadAuth和UploadAddress初始化OSS客户端
  13. $ossClient = init_oss_client($uploadAuth, $uploadAddress);
  14. // 上传文件,注意是同步上传会阻塞等待,耗时与文件大小和网络上行带宽有关
  15. //$result = upload_local_file($ossClient, $uploadAddress, $localFile);
  16. $result = multipart_upload_file($ossClient, $uploadAddress, $localFile);
  17. printf("Succeed, VideoId: %s", $videoId);
  18. } catch (Exception $e) {
  19. // var_dump($e);
  20. printf("Failed, ErrorMessage: %s", $e->getMessage());
  21. }

GO上传示例

环境准备

  • 支持 Go 1.7 及以上版本,可到 Go官网 下载合适的版本安装。

安装

  • 使用go get安装SDK

    1. go get -u github.com/aliyun/alibaba-cloud-sdk-go/sdk

    说明:

    • 安装过程中,界面不会打印提示,请耐心等待。如发生超时,请再次执行命令。
    • GOPATH 对应的目录下出现了子目录 src/github.com/aliyun/alibaba-cloud-sdk-go/services/vod 即表示SDK安装成功。
  • 使用glide安装SDK

    1. glide get github.com/aliyun/alibaba-cloud-sdk-go

参考代码

  • 定义核心步骤的函数:

1. 使用AK初始化VOD客户端

  1. func InitVodClient(accessKeyId string, accessKeySecret string) (client *vod.Client, err error) {
  2. // 点播服务接入区域
  3. regionId := "cn-shanghai"
  4. // 创建授权对象
  5. credential := &credentials.AccessKeyCredential{
  6. accessKeyId,
  7. accessKeySecret,
  8. }
  9. // 自定义config
  10. config := sdk.NewConfig()
  11. config.AutoRetry = true // 失败是否自动重试
  12. config.MaxRetryTime = 3 // 最大重试次数
  13. config.Timeout = 3000000000 // 连接超时,单位:纳秒;默认为3秒
  14. // 创建vodClient实例
  15. return vod.NewClientWithOptions(regionId, config, credential)
  16. }

2. 获取视频上传地址和凭证

  1. func MyCreateUploadVideo(client *vod.Client) (response *vod.CreateUploadVideoResponse, err error) {
  2. request := vod.CreateCreateUploadVideoRequest()
  3. request.Title = "Sample Video Title"
  4. request.Description = "Sample Description"
  5. request.FileName = "/opt/video/sample/video_file.mp4"
  6. //request.CateId = "-1"
  7. request.CoverURL = "http://img.alicdn.com/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png"
  8. request.Tags = "tag1,tag2"
  9. request.AcceptFormat = "JSON"
  10. return client.CreateUploadVideo(request)
  11. }

3. 使用上传凭证和地址初始化OSS客户端(注意需要先Base64解码并Json Decode再传入)

  1. func InitOssClient(uploadAuthDTO UploadAuthDTO, uploadAddressDTO UploadAddressDTO) (*oss.Client, error) {
  2. client, err := oss.New(uploadAddressDTO.Endpoint,
  3. uploadAuthDTO.AccessKeyId,
  4. uploadAuthDTO.AccessKeySecret,
  5. oss.SecurityToken(uploadAuthDTO.SecurityToken),
  6. oss.Timeout(86400*7, 86400*7))
  7. return client, err
  8. }

4. 上传本地文件

  1. func UploadLocalFile(client *oss.Client, uploadAddressDTO UploadAddressDTO, localFile string) {
  2. // 获取存储空间。
  3. bucket, err := client.Bucket(uploadAddressDTO.Bucket)
  4. if err != nil {
  5. fmt.Println("Error:", err)
  6. os.Exit(-1)
  7. }
  8. // 上传本地文件。
  9. err = bucket.PutObjectFromFile(uploadAddressDTO.FileName, localFile)
  10. if err != nil {
  11. fmt.Println("Error:", err)
  12. os.Exit(-1)
  13. }
  14. }

5. 刷新上传凭证

  1. func MyRefreshUploadVideo(client *vod.Client) (response *vod.RefreshUploadVideoResponse, err error) {
  2. request := vod.CreateRefreshUploadVideoRequest()
  3. request.VideoId = ""
  4. request.AcceptFormat = "JSON"
  5. return client.RefreshUploadVideo(request)
  6. }
  • 执行完整流程(注意捕获异常):
  1. type UploadAuthDTO struct {
  2. AccessKeyId string
  3. AccessKeySecret string
  4. SecurityToken string
  5. }
  6. type UploadAddressDTO struct {
  7. Endpoint string
  8. Bucket string
  9. FileName string
  10. }
  11. func main() {
  12. var accessKeyId string = "<AccessKeyId>"; // 您的AccessKeyId
  13. var accessKeySecret string = "<AccessKeySecret>"; // 您的AccessKeySecret
  14. var localFile string = "/Users/yours/Video/testVideo.flv"; // 需要上传到VOD的本地视频文件的完整路径
  15. // 初始化VOD客户端并获取上传地址和凭证
  16. var vodClient, initVodClientErr = InitVodClient(accessKeyId, accessKeySecret)
  17. if initVodClientErr != nil {
  18. fmt.Println("Error:", initVodClientErr)
  19. return
  20. }
  21. // 获取上传地址和凭证
  22. var response, createUploadVideoErr = MyCreateUploadVideo(vodClient)
  23. if createUploadVideoErr != nil {
  24. fmt.Println("Error:", createUploadVideoErr)
  25. return
  26. }
  27. // 执行成功会返回VideoId、UploadAddress和UploadAuth
  28. var videoId = response.VideoId
  29. var uploadAuthDTO UploadAuthDTO
  30. var uploadAddressDTO UploadAddressDTO
  31. var uploadAuthDecode, _ = base64.StdEncoding.DecodeString(response.UploadAuth)
  32. var uploadAddressDecode, _ = base64.StdEncoding.DecodeString(response.UploadAddress)
  33. json.Unmarshal(uploadAuthDecode, &uploadAuthDTO)
  34. json.Unmarshal(uploadAddressDecode, &uploadAddressDTO)
  35. // 使用UploadAuth和UploadAddress初始化OSS客户端
  36. var ossClient, _ = InitOssClient(uploadAuthDTO, uploadAddressDTO)
  37. // 上传文件,注意是同步上传会阻塞等待,耗时与文件大小和网络上行带宽有关
  38. UploadLocalFile(ossClient, uploadAddressDTO, localFile)
  39. //MultipartUploadFile(ossClient, uploadAddressDTO, localFile)
  40. fmt.Println("Succeed, VideoId:", videoId)
  41. }

.NET上传示例

环境准备

  • .NET Framework 4.6.1 及其以上版本
  • .NET Standard 2.0 及其以上版本

更多信息可参考 环境要求

安装

  • NuGet方式安装在 解决方案资源管理器面板 中右击您的项目选择 管理 NuGet 程序包 菜单,在打开的NuGet 管理面板 中点击 浏览 选项卡分别输入 aliyun-net-sdk-core 和 aliyun-net-sdk-vod,选择对应模块最新版本点击 安装 即可。

  • .NET CLI工具安装

  1. dotnet add package aliyun-net-sdk-core
  2. dotnet add package aliyun-net-sdk-vod

更多信息可参考VOD .NET SDK安装OSS .NET SDK安装

参考代码

  • 定义核心步骤的函数:

1. 使用AK初始化VOD客户端

  1. public static DefaultAcsClient InitVodClient(string accessKeyId, string accessKeySecret)
  2. {
  3. // 点播服务所在的Region,国内请填cn-shanghai
  4. string regionId = "cn-shanghai";
  5. IClientProfile profile = DefaultProfile.GetProfile(regionId, accessKeyId, accessKeySecret);
  6. return new DefaultAcsClient(profile);
  7. }

2. 获取视频上传地址和凭证

  1. public static CreateUploadVideoResponse CreateUploadVideo(DefaultAcsClient vodClient)
  2. {
  3. CreateUploadVideoRequest request = new CreateUploadVideoRequest();
  4. request.AcceptFormat = Aliyun.Acs.Core.Http.FormatType.JSON;
  5. request.FileName = "vod_test.mp4";
  6. request.Title = "this is title";
  7. //request.Description = "this is desc";
  8. //request.Tags = "tag1,tag2";
  9. //request.CoverURL = "http://vod.aliyun.com/test_cover_url.jpg";
  10. //request.CateId = -1;
  11. //request.TemplateGroupId = "";
  12. //request.WorkflowId = "";
  13. //request.StorageLocation = "";
  14. //request.AppId = "app-1000000";
  15. //设置请求超时时间
  16. request.SetReadTimeoutInMilliSeconds(1000);
  17. request.SetConnectTimeoutInMilliSeconds(1000);
  18. return vodClient.GetAcsResponse(request);
  19. }

3. 使用上传凭证和地址初始化OSS客户端(注意需要先Base64解码并Json Decode再传入)

  1. public static OssClient InitOssClient(JObject uploadAuth, JObject uploadAddress)
  2. {
  3. string endpoint = uploadAddress.GetValue("Endpoint").ToString();
  4. string accessKeyId = uploadAuth.GetValue("AccessKeyId").ToString();
  5. string accessKeySecret = uploadAuth.GetValue("AccessKeySecret").ToString();
  6. string securityToken = uploadAuth.GetValue("SecurityToken").ToString();
  7. return new OssClient(endpoint, accessKeyId, accessKeySecret, securityToken);
  8. }

4. 上传本地文件

  1. public static void UploadLocalFile(OssClient ossClient, JObject uploadAddress, string localFile)
  2. {
  3. string bucketName = uploadAddress.GetValue("Bucket").ToString();
  4. string objectName = uploadAddress.GetValue("FileName").ToString();
  5. ossClient.PutObject(bucketName, objectName, localFile);
  6. }

5. 刷新上传凭证

  1. public static RefreshUploadVideoResponse RefreshUploadVideo(DefaultAcsClient vodClient)
  2. {
  3. RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
  4. request.AcceptFormat = Aliyun.Acs.Core.Http.FormatType.JSON;
  5. request.VideoId = "VideoId";
  6. //设置请求超时时间
  7. request.SetReadTimeoutInMilliSeconds(1000);
  8. request.SetConnectTimeoutInMilliSeconds(1000);
  9. return vodClient.GetAcsResponse(request);
  10. }
  • 执行完整流程(注意捕获异常):
  1. //您的AccessKeyId
  2. string accessKeyId = "<Your AccessKeyId>";
  3. //您的AccessKeySecret
  4. string accessKeySecret = "<Your AccessKeySecret>";
  5. //需要上传到VOD的本地视频文件的完整路径,需要包含文件扩展名
  6. string localFile = "/Users/yours/Video/testVideo.flv";
  7. try {
  8. // 初始化VOD客户端并获取上传地址和凭证
  9. DefaultAcsClient vodClient = InitVodClient(accessKeyId, accessKeySecret);
  10. CreateUploadVideoResponse createUploadVideoResponse = CreateUploadVideo(vodClient);
  11. // 执行成功会返回VideoId、UploadAddress和UploadAuth
  12. String videoId = createUploadVideoResponse.VideoId;
  13. JObject uploadAuth = JObject.Parse(Base64Decode(createUploadVideoResponse.UploadAuth));
  14. JObject uploadAddress = JObject.Parse(Base64Decode(createUploadVideoResponse.UploadAddress));
  15. // 使用UploadAuth和UploadAddress初始化OSS客户端
  16. OssClient ossClient = InitOssClient(uploadAuth, uploadAddress);
  17. // 上传文件,注意是同步上传会阻塞等待,耗时与文件大小和网络上行带宽有关
  18. UploadLocalFile(ossClient, uploadAddress, localFile);
  19. Console.WriteLine("Put local file succeed, VideoId : " + videoId);
  20. }
  21. catch (Exception e)
  22. {
  23. Console.WriteLine("Put local file fail, ErrorMessage : " + e.Message);
  24. }

Java上传示例

环境准备

  • 环境要求

    使用Java 1.8及以上版本。

  • 查看版本

    执行命令java -version查看Java版本。

安装

在Maven项目中加入依赖项在 Maven 工程中使用 OSS Java SDK,只需在 pom.xml 中加入相应依赖即可。以 2.8.3 版本为例,在 内加入如下内容:

  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>aliyun-java-sdk-core</artifactId>
  4. <version>4.3.3</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.google.code.gson</groupId>
  8. <artifactId>gson</artifactId>
  9. <version>2.8.2</version>
  10. </dependency>
  11. <dependency>
  12. <groupId>com.aliyun.oss</groupId>
  13. <artifactId>aliyun-sdk-oss</artifactId>
  14. <version>3.1.0</version>
  15. </dependency>
  16. <dependency>
  17. <groupId>com.aliyun</groupId>
  18. <artifactId>aliyun-java-sdk-vod</artifactId>
  19. <version>2.15.2</version>
  20. </dependency>
  21. <dependency>
  22. <groupId>com.alibaba</groupId>
  23. <artifactId>fastjson</artifactId>
  24. <version>1.2.28</version>
  25. </dependency>
  26. <dependency>
  27. <groupId>org.json</groupId>
  28. <artifactId>json</artifactId>
  29. <version>20170516</version>
  30. </dependency>
  31. <dependency>
  32. <groupId>org.apache.commons</groupId>
  33. <artifactId>commons-lang3</artifactId>
  34. <version>3.4</version>
  35. </dependency>

更多信息可参考VOD Java SDKOSS Java SDK

参考代码

  • 定义核心步骤的函数:

1. 使用AK初始化VOD客户端

  1. public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {
  2. // 点播服务接入区域,国内请填cn-shanghai,其他区域请参考文档[点播中心](~~98194~~)
  3. String regionId = "cn-shanghai";
  4. DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
  5. DefaultAcsClient client = new DefaultAcsClient(profile);
  6. return client;
  7. }

2. 获取视频上传地址和凭证

  1. public static CreateUploadVideoResponse createUploadVideo(DefaultAcsClient vodClient) {
  2. CreateUploadVideoRequest request = new CreateUploadVideoRequest();
  3. request.setFileName("vod_test.mp4");
  4. request.setTitle("this is title");
  5. //request.setDescription("this is desc");
  6. //request.setTags("tag1,tag2");
  7. //request.setCoverURL("http://vod.aliyun.com/test_cover_url.jpg");
  8. //request.setCateId(-1L);
  9. //request.setTemplateGroupId("");
  10. //request.setWorkflowId("");
  11. //request.setStorageLocation("");
  12. //request.setAppId("app-1000000");
  13. //设置请求超时时间
  14. request.setSysReadTimeout(1000);
  15. request.setSysConnectTimeout(1000);
  16. return vodClient.getAcsResponse(request);
  17. }

3. 使用上传凭证和地址初始化OSS客户端(注意需要先Base64解码并Json Decode再传入)

  1. public static OSSClient initOssClient(JSONObject uploadAuth, JSONObject uploadAddress) {
  2. String endpoint = uploadAddress.getString("Endpoint");
  3. String accessKeyId = uploadAuth.getString("AccessKeyId");
  4. String accessKeySecret = uploadAuth.getString("AccessKeySecret");
  5. String securityToken = uploadAuth.getString("SecurityToken");
  6. return new OSSClient(endpoint, accessKeyId, accessKeySecret, securityToken);
  7. }

4. 上传本地文件

  1. public static void uploadLocalFile(OSSClient ossClient, JSONObject uploadAddress, String localFile){
  2. String bucketName = uploadAddress.getString("Bucket");
  3. String objectName = uploadAddress.getString("FileName");
  4. File file = new File(localFile);
  5. ossClient.putObject(bucketName, objectName, file);
  6. }

5. 刷新上传凭证

  1. public static RefreshUploadVideoResponse refreshUploadVideo(DefaultAcsClient vodClient) throws ClientException {
  2. RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
  3. request.setAcceptFormat(FormatType.JSON);
  4. request.setVideoId("VideoId");
  5. //设置请求超时时间
  6. request.setSysReadTimeout(1000);
  7. request.setSysConnectTimeout(1000);
  8. return vodClient.getAcsResponse(request);
  9. }
  • 执行完整流程(注意捕获异常):
  1. import com.alibaba.fastjson.JSONObject;
  2. import com.aliyun.oss.OSSClient;
  3. import com.aliyuncs.DefaultAcsClient;
  4. import com.aliyuncs.exceptions.ClientException;
  5. import com.aliyuncs.http.FormatType;
  6. import com.aliyuncs.profile.DefaultProfile;
  7. import com.aliyuncs.vod.model.v20170321.CreateUploadVideoRequest;
  8. import com.aliyuncs.vod.model.v20170321.CreateUploadVideoResponse;
  9. import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoRequest;
  10. import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoResponse;
  11. import org.apache.commons.codec.binary.Base64;
  12. import java.io.File;
  13. public class UploadDemo {
  14. public static void main(String[] argv) {
  15. //您的AccessKeyId
  16. String accessKeyId = "<Your AccessKeyId>";
  17. //您的AccessKeySecret
  18. String accessKeySecret = "<Your AccessKeySecret>";
  19. //需要上传到VOD的本地视频文件的完整路径,需要包含文件扩展名
  20. String localFile = "/Users/yours/Video/testVideo.flv";
  21. try {
  22. // 初始化VOD客户端并获取上传地址和凭证
  23. DefaultAcsClient vodClient = initVodClient(accessKeyId, accessKeySecret);
  24. CreateUploadVideoResponse createUploadVideoResponse = createUploadVideo(vodClient);
  25. // 执行成功会返回VideoId、UploadAddress和UploadAuth
  26. String videoId = createUploadVideoResponse.getVideoId();
  27. JSONObject uploadAuth = JSONObject.parseObject(decodeBase64(createUploadVideoResponse.getUploadAuth()));
  28. JSONObject uploadAddress = JSONObject.parseObject(decodeBase64(createUploadVideoResponse.getUploadAddress()));
  29. // 使用UploadAuth和UploadAddress初始化OSS客户端
  30. OSSClient ossClient = initOssClient(uploadAuth, uploadAddress);
  31. // 上传文件,注意是同步上传会阻塞等待,耗时与文件大小和网络上行带宽有关
  32. uploadLocalFile(ossClient, uploadAddress, localFile);
  33. System.out.println("Put local file succeed, VideoId : " + videoId);
  34. } catch (Exception e) {
  35. System.out.println("Put local file fail, ErrorMessage : " + e.getLocalizedMessage());
  36. }
  37. }
  38. }

Demo下载

PHP上传Demo

可下载完整的 PHP版上传Demo源码,更多使用信息请参考 OSS-PHP-SDK上传文件

GO上传Demo

可下载完整的GO版上传Demo源码,更多使用信息请参考 OSS-GO-SDK上传文件

.NET上传Demo

可下载完整的.NET版上传Demo源码,更多使用信息请参考 OSS-.NET-SDK上传文件

Java上传Demo

可下载完整的Java版上传Demo源码更多使用信息请参考 OSS-Java-SDK上传文件

其它语言上传Demo