VOD provides an SDK for uploading videos from iOS clients. For details about the upload process, see Guide.
TXUGCUploadDemo
folder. The source code is in TXUGCUploadDemo/upload
.Copy TXUGCUploadDemo/upload
to your project.
Import the dynamic libraries QCloudCore.framework
and QCloudCOSXML.framework
in TXUGCUploadDemo/upload/COSSDK/
into your project and add the following dependencies:
1. CoreTelephony.framework
2. Foundation.framework
3. SystemConfiguration.framework
4. libc++.tbd
Under the Build Settings tab, add -ObjC
to Other Linker Flags.
TXUGCPublish *_videoPublish = [[TXUGCPublish alloc] initWithUserID:@"upload_video_userid"];
_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);
}
TXPublishParam *publishParam = [[TXPublishParam alloc] init];
publishParam.signature = @"Signature generated by your business backend";
publishParam.videoPath = @"Path of the video file";
For details on how to calculate signature
, please see Signature for Upload from Client.
[_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.
To upload a thumbnail, pass in the thumbnail path.
TXPublishParam *publishParam = [[TXPublishParam alloc] init];
publishParam.signature = @"Signature generated by your business backend";
publishParam.coverPath = @"Path of the thumbnail image";
publishParam.videoPath = @"Path of the video file";
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.
The SDK supports automatic checkpoint restart. If an upload is interrupted, you can resume the upload from where it left off.
With checkpoint restart, if an upload is interrupted, it can be resumed from where it left off within one day. After one day passes, the upload cannot be resumed, and the file can only be reuploaded from the beginning.
You can use the enableResume
parameter to enable or disable checkpoint start. It’s enabled by default.
To enable HTTPS upload, set enableHTTPS
in TXPublishParam
to true
.
TXPublishParam *publishParam = [[TXPublishParam alloc] init];
publishParam.enableHTTPS = true;
// 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 = @"Signature generated by your business backend";
publishParam.mediaPath = @"Path of the image file";
// Upload an image or media file
[_imagePublish publishMedia:publishParam];
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 | Signature for Upload from Client. | NSString* | Yes |
videoPath | The path of the local video file. | NSString* | Yes |
coverPath | The path of a local thumbnail image. | NSString* | No |
fileName | The name of the uploaded file in Tencent Cloud. If this parameter is left empty, the original name of the local file 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 |
TXUGCPublish.delegate
: Set upload callbacks
Member variable | Description | Type | Required |
---|---|---|---|
delegate | The upload progress and result callbacks. | TXVideoPublishListener | Yes |
onPublishProgress
: The upload progress callback
Variable | Description | Type |
---|---|---|
uploadBytes | Uploaded bytes. | NSInteger |
totalBytes | Total bytes. | NSInteger |
onPublishComplete
: The upload result callback
Variable | Description | Type |
---|---|---|
result | The upload result. | TXPublishResult |
onPublishEvent
: The upload event callback
Variable | Description | Type |
---|---|---|
evt | 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 | Signature for Upload from Client. | NSString | Yes |
The SDK listens for video upload status using TXVideoPublishListener
. Therefore, to get the upload status, check retCode
in TXPublishResult
.
Code | TVCCommon Constant | Description |
---|---|---|
0 | TVC_OK | Uploaded successfully. |
1001 | TVC_ERR_UGC_REQUEST_FAILED | The upload request failed, usually due to invalid or expired client signature. Please get the signature again. |
1002 | TVC_ERR_UGC_PARSE_FAILED | Failed to parse the request information. |
1003 | TVC_ERR_VIDEO_UPLOAD_FAILED | Failed to upload the video. |
1004 | TVC_ERR_COVER_UPLOAD_FAILED | Failed to upload the thumbnail. |
1005 | TVC_ERR_UGC_FINISH_REQ_FAILED | Failed to end the upload. |
1006 | TVC_ERR_UGC_FINISH_RSP_FAILED | A response error occurred when ending the upload. |
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 | Signature for Upload from Client. | 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 name of the local file 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 |
TXUGCPublish.TXMediaPublishListener
: Set upload callbacks
Member variable | Description | Type | Required |
---|---|---|---|
mediaDelegate | The upload progress and result callbacks. | TXMediaPublishListener | Yes |
onMediaPublishProgress
: The upload progress callback
Variable | Description | Type |
---|---|---|
uploadBytes | Uploaded bytes. | NSInteger |
totalBytes | Total bytes. | NSInteger |
onMediaPublishComplete
: The upload result callback
Variable | Description | Type |
---|---|---|
result | The upload result. | TXMediaPublishResult |
onMediaPublishEvent
: The upload event callback
Variable | Description | Type |
---|---|---|
evt | 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 media file ID. | NSString |
mediaURL | The URL of the media file. | NSString |
TXUGCPublishOptCenter.prepareUpload
: Set up pre-upload
Parameter | Description | Type | Required |
---|---|---|---|
signature | Signature for Upload from Client. | NSString | Yes |
The SDK listens for video upload status using TXMediaPublishListener
. Therefore, to get the upload status, check retCode
in TXMediaPublishResult
.
Code | TVCCommon Constant | Description |
---|---|---|
0 | MEDIA_PUBLISH_RESULT_OK | Uploaded successfully. |
1001 | MEDIA_PUBLISH_RESULT_UPLOAD_REQUEST_FAILED | The upload request failed, usually due to invalid or expired client signature. Please get the signature again. |
1002 | MEDIA_PUBLISH_RESULT_UPLOAD_RESPONSE_ERROR | Failed to parse the request information. |
1003 | MEDIA_PUBLISH_RESULT_UPLOAD_VIDEO_FAILED | Failed to upload the media file. |
1005 | MEDIA_PUBLISH_RESULT_PUBLISH_REQUEST_FAILED | Failed to end the upload. |
1006 | MEDIA_PUBLISH_RESULT_PUBLISH_RESPONSE_ERROR | A response error occurred when ending the upload. |
Was this page helpful?