TXUGCUploadDemo
folder. The source code is in TXUGCUploadDemo/upload
.TXUGCUploadDemo/upload
to your project.QCloudCore.framework
and QCloudCOSXML.framework
in TXUGCUploadDemo/upload/COSSDK/
into your project and add the following dependencies:1. CoreTelephony.framework2. Foundation.framework3. SystemConfiguration.framework4. libc++.tbd
-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;
// 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 |
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 |
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 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 |
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 | 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 image/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?