tencent cloud

Feedback

Upload SDK for iOS

Last updated: 2024-05-16 14:45:20
    Upload VOD provides an SDK for uploading videos from iOS clients. For details about the upload process, see Guide.
    SDK name
    Vod Upload SDK For IOS
    Version
    V1.1.23.0
    SDK Introduce
    Providing a scenario for end-users of an app to upload local videos to a cloud video on demand platform:
    Developer
    Tencent Cloud Computing (Beijing) Co., Ltd.
    Download SDK
    1. Click to download the iOS upload Demo and source code, unzip the downloaded package, and you can see the Demo directory.
    2. Upload the source code in the Demo/app/src/main/java/com/tencent/ugcupload/demo/videoupload directory.

    Integrating the Source code and Libraries

    1. Copy TXUGCUploadDemo/upload to your project.
    2. Add the following dependency to your Podfile:
    pod 'QCloudQuic','6.3.7'
    pod 'QCloudCOSXML/Slim','6.3.7'
    // Based on your project, the dependency is already available,
    // so there is no need to add it additionally.
    pod 'AFNetworking','4.0.1'
    3. Under the Build Settings tab, add -ObjC to Other Linker Flags.

    Uploading Videos

    Initialize an upload object

    TXUGCPublish *_videoPublish = [[TXUGCPublish alloc] initWithUserID:@"upload_video_userid"];

    Set the upload object callback

    _videoPublish.delegate = self;
    #pragma mark - TXVideoPublishListener
    
    - (void)onPublishProgress:(NSInteger)uploadBytes totalBytes:(NSInteger)totalBytes {
    self.progressView.progress = (float)uploadBytes/totalBytes;
    NSLog(@"onPublishProgress [%ld/%ld]", uploadBytes, totalBytes);
    }
    
    - (void)onPublishComplete:(TXPublishResult*)result {
    NSString *string = [NSString stringWithFormat:@"Upload completed; error code: [%d], error message: [%@]", result.retCode, result.retCode == 0? result.videoURL: result.descMsg];
    [self showErrorMessage:string];
    NSLog(@"onPublishComplete [%d/%@]", result.retCode, result.retCode == 0? result.videoURL: result.descMsg);
    }

    Construct upload parameters

    TXPublishParam *publishParam = [[TXPublishParam alloc] init];
    
    publishParam.signature = @"The signature generated by your business backend";
    publishParam.videoPath = @"The path of the video file";
    For details on how to calculate the signature, see Signature for Upload from Client.

    Call the upload API

    [_videoPublish publishVideo:publishParam];
    Note:
    The upload API automatically selects simple upload or multipart upload based on the file size. You don’t need to manually set up multipart upload.
    To upload to a subapplication, see Subapplication System - Upload from client.

    Advanced Features

    Uploading a thumbnail

    To upload a thumbnail, pass in the thumbnail path.
    TXPublishParam *publishParam = [[TXPublishParam alloc] init];
    publishParam.signature = @"The signature generated by your business backend";
    publishParam.coverPath = @"The path of the thumbnail image";
    publishParam.videoPath = @"The path of the video file";

    Canceling and resuming upload

    To cancel an upload, call the cancelPublish API.
    [_videoPublish cancelPublish];
    To resume an upload, call publishVideo of TXUGCPublish again, passing in the same upload parameters and video and thumbnail paths.

    Setting up checkpoint restart

    VOD supports checkpoint restart. If an upload is interrupted, when you upload the same file again, the upload can start from where it left off. This works only if a file is uploaded again within one day. If the interval exceeds one day, you will need to upload the full video again.
    You can use the enableResume parameter to enable or disable checkpoint start. It’s enabled by default.

    Enabling HTTPS upload

    To enable HTTPS upload, set enableHTTPS in TXPublishParam to true.
    TXPublishParam *publishParam = [[TXPublishParam alloc] init];
    publishParam.enableHTTPS = true;

    Turn off logs

    Turning off logs needs to be done through the setIsDebug method of TXUGCPublish, which is enabled by default. When enabled, logcat logs will be printed, and logs will also be saved to the app's private directory.
    // NO: Turn off logs
    [_videoPublish setIsDebug:NO];
    

    Uploading Images and Other Media Files

    // Create an object
    TXUGCPublish *_imagePublish = [[TXUGCPublish alloc] initWithUserID:@"upload_image_userid"];
    
    // Set the callback
    _imagePublish.mediaDelegate = self;
    
    // Construct upload parameters
    TXMediaPublishParam *publishParam = [[TXMediaPublishParam alloc] init];
    publishParam.signature = @"The signature generated by your business backend";
    publishParam.mediaPath = @"Path of the image file";
    
    // Upload an image or media file
    [_imagePublish publishMedia:publishParam];
    

    Video Upload APIs

    TXUGCPublish::initWithUserID: Initialize an upload object
    Parameter
    Description
    Type
    Required
    userID
    The user ID.
    NSString
    No
    TXUGCPublish.publishVideo: Upload a video
    Parameter
    Description
    Type
    Required
    param
    The publishing parameters.
    TXPublishParam
    Yes
    TXPublishParam: Upload parameters
    Parameter
    Description
    Type
    Required
    signature
    NSString*
    YES
    videoPath
    The path of the local video file.
    NSString*
    YES
    coverPath
    The path of the local thumbnail image (optional).
    NSString*
    NO
    fileName
    The name of the uploaded file in Tencent Cloud. If this parameter is left empty, the original filename will be used.
    NSString*
    NO
    enableResume
    Whether to enable checkpoint restart. It’s enabled by default.
    BOOL
    NO
    enableHttps
    Whether to enable HTTPS. It’s disabled by default.
    BOOL
    NO
    fileName
    The name of the video file uploaded to Tencent Cloud, if not filled, the default is the local file name.
    String
    NO
    enablePreparePublish
    Whether to enable the pre-upload mechanism, default is enabled. The pre-upload mechanism can significantly improve the upload quality of files
    boolean
    NO
    sliceSize
    Chunk size, supports a minimum of 1MB and a maximum of 10MB, default is the uploaded file size divided by 10
    long
    NO
    concurrentCount
    The maximum number of concurrent uploads for chunked uploads, default is 4.
    int
    NO
    trafficLimit
    The speed limit value setting range is 819200 ~ 838860800, that is, 100KB/s ~ 100MB/s. If it exceeds this range, a 400 error will be returned. It is not recommended to set this value too small to prevent timeouts. -1 indicates no speed limit.
    long
    NO
    uploadResumeController
    The resume controller, which can be customized to calculate and save the resume key values, defaults to using MD5 to calculate the file key values.
    IUploadResumeController
    NO
    TXUGCPublish.delegate: Set upload callbacks
    Member variable
    Description
    Type
    Required
    delegate
    The upload progress and result callbacks.
    TXVideoPublishListener
    Yes
    onPublishProgress: The upload progress callback
    Member variable
    Description
    Type
    uploadBytes
    Uploaded bytes.
    NSInteger
    totalBytes
    Total bytes.
    NSInteger
    onPublishComplete: The upload result callback
    Member variable
    Description
    Type
    result
    The upload result.
    TXPublishResult
    onPublishEvent: The upload event callback
    Member variable
    Description
    Type
    evt
    The upload event, which can be printed and used for debugging.
    NSDictionary
    TXPublishResult: The upload result
    Member variable
    Description
    Type
    retCode
    The error code
    int
    descMsg
    The error message.
    NSString
    videoId
    The VOD file ID.
    NSString
    videoURL
    The video URL.
    NSString
    coverURL
    The thumbnail URL.
    NSString
    TXUGCPublishOptCenter.prepareUpload: Set up pre-upload
    Parameter
    Description
    Type
    Required
    signature
    NSString
    Yes

    Image and Other Media Upload APIs

    TXUGCPublish::initWithUserID: Initialize an upload object
    Parameter
    Description
    Type
    Required
    userID
    The user ID.
    NSString
    No
    TXUGCPublish.publishMedia: Start an upload
    Parameter
    Description
    Type
    Required
    param
    The publishing parameters.
    TXMediaPublishParam
    Yes
    TXMediaPublishParam: Upload parameters
    Parameter
    Description
    Type
    Required
    signature
    NSString*
    YES
    mediaPath
    The path of the local media file.
    NSString*
    YES
    fileName
    The name of the uploaded file in Tencent Cloud. If this parameter is left empty, the original filename will be used.
    NSString*
    NO
    enableResume
    Whether to enable checkpoint restart. It’s enabled by default.
    BOOL
    NO
    enableHttps
    Whether to enable HTTPS. It’s disabled by default.
    BOOL
    NO
    fileName
    The name of the video file uploaded to Tencent Cloud, if not filled, the default is the local file name.
    String
    NO
    enablePreparePublish
    Whether to enable the pre-upload mechanism, default is enabled. The pre-upload mechanism can significantly improve the upload quality of files
    boolean
    NO
    sliceSize
    Chunk size, supports a minimum of 1MB and a maximum of 10MB, default is the uploaded file size divided by 10
    long
    NO
    concurrentCount
    The maximum number of concurrent uploads for chunked uploads, default is 4.
    int
    NO
    trafficLimit
    The speed limit value setting range is 819200 ~ 838860800, that is, 100KB/s ~ 100MB/s. If it exceeds this range, a 400 error will be returned. It is not recommended to set this value too small to prevent timeouts. -1 indicates no speed limit.
    long
    NO
    uploadResumeController
    The resume controller, which can be customized to calculate and save the resume key values, defaults to using MD5 to calculate the file key values.
    IUploadResumeController
    NO
    TXUGCPublish.TXMediaPublishListener: Set upload callbacks
    Member variable
    Description
    Type
    Required
    mediaDelegate
    The upload progress and result callbacks.
    TXMediaPublishListener
    Yes
    onMediaPublishProgress: The upload progress callback
    Member variable
    Description
    Type
    uploadBytes
    Uploaded bytes.
    NSInteger
    totalBytes
    Total bytes.
    NSInteger
    onMediaPublishComplete: The upload result callback
    Member variable
    Description
    Type
    result
    The upload result.
    TXMediaPublishResult
    onMediaPublishEvent: The upload event callback
    Member variable
    Description
    Type
    evt
    The upload event, which can be printed and used for debugging.
    NSDictionary
    TXMediaPublishResult: The upload result
    Member variable
    Description
    Type
    retCode
    The error code.
    int
    descMsg
    The error message.
    NSString
    mediaId
    The file ID of the image/media file.
    NSString
    mediaURL
    The URL of the image/media file.
    NSString
    TXUGCPublishOptCenter.prepareUpload: Set up pre-upload
    Parameter
    Description
    Type
    Required
    signature
    NSString
    Yes

    Error codes

    The SDK listens for video upload status using TXMediaPublishListener. Therefore, to get the upload status, check retCode in TXMediaPublishResult.
    Error Codes
    TVCCommon Constant
    Description
    0
    TVC_OK
    Uploaded successfully.
    1001
    TVC_ERR_UGC_REQUEST_FAILED
    The upload request failed, usually because the client signature has expired or is invalid. The app needs to reapply for a signature.
    1002
    TVC_ERR_UGC_PARSE_FAILED
    Request information parsing failed.
    1003
    TVC_ERR_VIDEO_UPLOAD_FAILED
    Upload video failed.
    1004
    TVC_ERR_COVER_UPLOAD_FAILED
    Upload cover failed.
    1005
    TVC_ERR_UGC_FINISH_REQ_FAILED
    Failed to end upload request.
    1006
    TVC_ERR_UGC_FINISH_RSP_FAILED
    End upload response error.
    1008
    TVC_ERR_FILE_NOT_EXIST
    The file does not exist at the specified file path.
    1009
    TVC_ERR_ERR_UGC_PUBLISHING
    The video is currently uploading.
    1010
    TVC_ERR_UGC_INVALID_PARAME
    Invalid parameter.
    1012
    TVC_ERR_INVALID_SIGNATURE
    Upload signature is empty.
    1013
    TVC_ERR_INVALID_VIDEOPATH
    Video path is empty.
    1017
    TVC_ERR_USER_CANCLE
    User initiated upload cancellation.
    1020
    TVC_ERR_UPLOAD_SIGN_EXPIRED
    Signature expired.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support