Polyv Help Center

Help Center

Java Upload SDK Documentation

Updated: 2025-10-10 12:02:04

The Polyv Java Upload SDK provides a development toolkit for server-side uploading of media files to the Polyv Cloud Video Platform.

Features

  • Quickly upload media files in various formats.
  • Support various settings during upload, such as file title, description, tags, upload directory, and whether to enable courseware optimization.
  • Use chunked concurrent upload with support for resumable upload.

Usage

Prerequisites

  1. Before using this SDK, you must activate the Polyv Cloud Video Service. If you are not familiar with this service, please visit the product homepage for details: Cloud Video.
  2. Obtain the userId, secretKey, and other related information for user identity verification. You can find this information on the "Cloud Video Management Console -> Settings -> API Interface" page. Click here to log in to the console.

Environment Requirements

Java version 1.8.0 or higher

Integrating the SDK

  1. Download the Java Upload SDK development package (including sample code and required jar files). Click here to download.
  2. Copy the extracted jar files to your project.
  3. The method for referencing jar files in an IDE is described below using Eclipse and IntelliJ IDEA as examples:

3.1 In Eclipse, select your project, right-click -> Properties -> Java Build Path -> Add JARs.

3.2 In IntelliJ IDEA, open your project, File -> Project Structure -> Modules -> Dependencies on the right -> + -> JARs or directories.

API Reference

1. Entry Class PolyvUploadClient.java

1.1 Constructor

PolyvUploadClient(String userId, String secretKey, int partitionSize, String checkpoint, int threadNum)

Parameter Explanation:

Parameter Description
userId Polyv account ID
secretKey Polyv account secretKey
partitionSize Specifies the size of each chunk during chunked upload, in bytes. Default is 1MB, range is 100KB to 5GB
checkpoint Local disk path for writing the checkpoint position during resumable upload. The file path must already exist
threadNum Specifies the number of concurrent threads for chunked upload. Default is 1. Note: This configuration consumes server CPU resources and should be set based on server conditions.

1.2 Upload Method

uploadVideoParts(VideoInfo videoInfo)

This method returns the video ID.

2. Video Entity Class VideoInfo.java

Video Information Fields:

Parameter Type Required Description
fileLocation String true Absolute local path of the video file, must include the file extension
title String false Video title. If empty, the video file name (without extension) will be used
fileSize Long false File size
describ String false Video description
tag String false Video tags, separated by commas if multiple
cataId Long false Video category ID. Default value: 1, meaning upload to the default category
luping Integer false Whether to enable courseware optimization processing. Default value: 0
keepsource Integer false Whether to keep the source file for playback. Default: 0
videoPoolId String false Video ID. Required to specify the vid for resuming an interrupted upload
state String false Custom extension field. If submitted, it will be transparently returned in the upload completion event callback.

Sample Code

import net.polyv.bean.vo.VideoInfo;
import net.polyv.callback.UploadCallBack;
import net.polyv.entry.PolyvUploadClient;
import net.polyv.enumeration.UploadErrorMsg;

public class PolyvUploadVideoDemo {
    private static final String userId = ""; //保利威账号的userId(必填)
    private static final String secretKey = ""; //账号的secretKey(必填)

    public static void main(String[] args) {
        int partitionSize = 1*1024 * 1024; //可指定分片上传时每个分片的大小,默认为1M
        int threadNum = 1; //可指定分片上传时的并发线程数,默认为1,(注:该配置会占用服务器CPU资源,需根据服务器情况指定)
        String checkpoint = "/Users/TestUser/Desktop"; //断点续传的上传位置写入路径
        PolyvUploadClient client = new PolyvUploadClient(userId, secretKey, partitionSize, checkpoint, threadNum); //初始化PolyvUploadClient实例

        VideoInfo videoInfo = new VideoInfo();
        videoInfo.setFileLocation("/Users/TestUser/Desktop/testVideo.mp4"); //视频文件在服务器上的绝对路径,必须包含拓展名(必填)
        videoInfo.setTitle("测试视频"); // 视频标题(必填)
        videoInfo.setCataId(1L); // 上传的分类目录,默认值:1,表示上传到默认分类(可选)
        videoInfo.setDescrib("视频描述"); // 视频描述(可选)
        videoInfo.setTag("视频标签"); // 视频标签(可选)
        videoInfo.setLuping(0); //是否进行课件优化处理,默认值:0(可选)
        videoInfo.setKeepSource(0); //是否保持源文件播放,默认:0(可选)
        videoInfo.setState("自定义拓展信息"); //如果提交了该字段,会在上传完成的事件回调中透传返回

        System.out.println("vid=" + client.uploadVideoParts(videoInfo, new UploadCallBack() {
            @Override
            public void start(String s) {
                System.out.println("start=" + s);
            }
            @Override
            public void process(String s, long l, long l1) {
                System.out.println("process=" + s + ",uploaded=" + l + ", total=" + l1);
            }
            @Override
            public void complete(String s) {
                System.out.println("complete=" + s);
            }
            @Override
            public void success(String s) {
                System.out.println("success=" + s);
            }

            @Override
            public void error(String s, UploadErrorMsg uploadErrorMsg) {
                System.out.println("error=" + s + ", message=" + uploadErrorMsg.getMessage());
            }
        }, true));
        // 当上传中断,重新恢复的时候,可以指定vid来恢复上传 videoInfo.setVideoPoolId("xxxxxxxxxxx");
        //     videoInfo = new VideoInfo();
        //     videoInfo.setFileLocation("C:\\Users\\Lenovo\\Desktop\\video\\test.mp4");
        //     videoInfo.setVideoPoolId("xxxxxxxxxxx");
        //     System.out.println("vid=" + client.uploadVideoParts(videoInfo), new UploadCallBack() {
        //         @Override
        //         public void start(String s) {
        //             System.out.println("start=" + s);
        //         }
        //         @Override
        //         public void process(String s, long l, long l1) {
        //             System.out.println("process=" + s + ",uploaded=" + l + ", total=" + l1);
        //         }
        //         @Override
        //         public void complete(String s) {
        //             System.out.println("complete=" + s);
        //         }
        //         @Override
        //         public void success(String s) {
        //             System.out.println("success=" + s);
        //         }
        //         @Override
        //         public void error(String s, UploadErrorMsg uploadErrorMsg) {
        //             System.out.println("error=" + s + ", message=" + uploadErrorMsg.getMessage());
        //         }
        //     }, true);
        // }
    }
}

Change Log

Date Version Update Content
2020-03-29 v1.1.1 Support for custom extension fields, transparently returned in upload completion callback
2019-08-05 v1.0.0 Release of the new Java Upload SDK supporting resumable upload
联系客服,在线咨询