SDK name | Vod Upload SDK For IOS |
Version | V1.2.5.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. |
TXUGCUploadDemo/upload
to your project.pod 'QCloudQuic','6.3.7'pod 'QCloudCOSXML/Slim','6.4.4'// Based on your project, the dependency is already available,// so there is no need to add it additionally.pod 'AFNetworking','4.0.1'
-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 = @"The signature generated by your business backend";publishParam.videoPath = @"The path of the video file";
[_videoPublish publishVideo:publishParam];
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";
cancelPublish
API.[_videoPublish cancelPublish];
publishVideo
of TXUGCPublish
again, passing in the same upload parameters and video and thumbnail paths.enableResume
parameter to enable or disable checkpoint start. It’s enabled by default.enableHTTPS
in TXPublishParam
to true
.TXPublishParam *publishParam = [[TXPublishParam alloc] init];publishParam.enableHTTPS = true;
// NO: Turn off logs[_videoPublish setIsDebug:NO];
// Create an objectTXUGCPublish *_imagePublish = [[TXUGCPublish alloc] initWithUserID:@"upload_image_userid"];// Set the callback_imagePublish.mediaDelegate = self;// Construct upload parametersTXMediaPublishParam *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];
TXUGCPublish::initWithUserID
: Initialize an upload objectParameter | Description | Type | Required |
userID | The user ID. | NSString | No |
TXUGCPublish.publishVideo
: Upload a videoParameter | Description | Type | Required |
param | The publishing parameters. | TXPublishParam | Yes |
TXPublishParam
: Upload parametersParameter | 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 callbacksMember variable | Description | Type | Required |
delegate | The upload progress and result callbacks. | TXVideoPublishListener | Yes |
onPublishProgress
: The upload progress callbackMember variable | Description | Type |
uploadBytes | Uploaded bytes. | NSInteger |
totalBytes | Total bytes. | NSInteger |
onPublishComplete
: The upload result callbackMember variable | Description | Type |
result | The upload result. | TXPublishResult |
onPublishEvent
: The upload event callbackMember variable | Description | Type |
evt | The upload event, which can be printed and used for debugging. | NSDictionary |
TXPublishResult
: The upload resultMember 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-uploadParameter | Description | Type | Required |
signature | NSString | Yes |
TXUGCPublish::initWithUserID
: Initialize an upload objectParameter | Description | Type | Required |
userID | The user ID. | NSString | No |
TXUGCPublish.publishMedia
: Start an uploadParameter | Description | Type | Required |
param | The publishing parameters. | TXMediaPublishParam | Yes |
TXMediaPublishParam
: Upload parametersParameter | 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 callbacksMember variable | Description | Type | Required |
mediaDelegate | The upload progress and result callbacks. | TXMediaPublishListener | Yes |
onMediaPublishProgress
: The upload progress callbackMember variable | Description | Type |
uploadBytes | Uploaded bytes. | NSInteger |
totalBytes | Total bytes. | NSInteger |
onMediaPublishComplete
: The upload result callbackMember variable | Description | Type |
result | The upload result. | TXMediaPublishResult |
onMediaPublishEvent
: The upload event callbackMember variable | Description | Type |
evt | The upload event, which can be printed and used for debugging. | NSDictionary |
TXMediaPublishResult
: The upload resultMember 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-uploadParameter | Description | Type | Required |
signature | NSString | Yes |
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. |
Was this page helpful?