在 SOFTLAYER(IBM Cloud) 中上传视频

Upload video in SOFTLAYER(IBM Cloud)

我必须使用 Objective C 在 SOFTLAYER(IBM Cloud) 服务器中上传视频。我正在使用 xcode7.2 和 Objective C。我不知道如何使用 Objective C 在云基础服务器中上传视频。当转到 SOFTLAYER API link 时,没有 iOS 或如何使用 Objective C 实施 SOFTLYAER 的指南。我的问题是如何在 Xcode 中集成 SOFTLAYER 以及如何实现它。

我正在添加 SOFTLAYER guide there is no guide for iOS.

的屏幕截图

如果有人使用 Objective C 在 SOFTLAYER 服务器上传视频,或者您对此有任何想法,请提供帮助。

提前致谢。

是的,正如您所写,所有 Softlayer 客户端都在这里:

https://github.com/softlayer

但是没有特定的客户端使用 objective-c 来管理对象存储,但是您可以使用简单的 rest 请求来管理 Softlayer 的对象存储并且能够成功上传您的视频,我很确定 Objective-C提供了一个API来处理REST请求。

您可以在此处查看有关使用 rest 管理对象存储的指南:

https://sldn.softlayer.com/blog/waelriac/managing-softlayer-object-storage-through-rest-apis

如果您有更多问题,请告诉我

此致

感谢@Nelson link Softlayer Object Storage access through rest api. From this link we can upload video in object storage directly from app. For more details you see this link Access Softlayer using Postman

我正在使用休息 api 调用在软层 object 存储中上传视频。我在 objective C 中使用 AFNetworking 调用 rest api。以下是简单的步骤:-

我的 authToken 是:- "AUTH_tk9eafc199756fabe8066f"

1) 从软层 object 存储服务器获取 "auth token" 和 "x-storage-url"。你可以通过使用 "Authentication Endpoint (public and private)" 这个 api 来得到它。在 header 字段中发送您的 "username" 和 "API Key (Password)"。

-(void)callRestAPI{

NSURL *URL = [NSURL URLWithString:@"https://sjc01.objectstorage.softlayer.net/auth/v1.0/"];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.requestSerializer =  [AFHTTPRequestSerializer serializer];
[manager.requestSerializer setValue:@"HJYBOS984353-3:ghym8435" forHTTPHeaderField:@"X-Auth-User"];
[manager.requestSerializer setValue:@"26704dbc93e5c39986da451e539857f6596dc9be18aad7a6b4dc2822f48e66f8" forHTTPHeaderField:@"X-Auth-Key"];
[manager GET:URL.absoluteString parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {

    NSHTTPURLResponse *response = ((NSHTTPURLResponse *)[task response]);
    NSDictionary *headers = [response allHeaderFields];
    authURL = [headers valueForKey:@"X-Storage-Url"];
    authToken = [headers valueForKey:@"X-Auth-Token"];
    NSLog(@"\nHeader Token:: %@ \n Header URL:: %@ \n",authToken,authURL);

    [PMCommonClass userDefaultValueSave:authToken key:SOFTLAYER_AUTH_TOKEN];
    [PMCommonClass userDefaultValueSave:authURL key:SOFTLAYER_AUTH_URL];

    NSDictionary *mainDict = [PMCommonClass jsonDictionaryFromResponse:responseObject];
    NSLog(@"Main Dict:: %@",mainDict);
} failure:^(NSURLSessionTask *operation, NSError *error) {
    NSLog(@"Error:: %@", error.localizedDescription);
}];
}

2) 之后 "auth token" 和 "x-Storage-url" 我们可以在 object 存储中创建容器。

-(void)createConatiner{
NSString *authUrl = @"https://sjc01.objectstorage.softlayer.net/v1/AUTH_695d079a-ead3-4045-b303-a1b123acdb3db";
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/Container6",authUrl]];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.requestSerializer =  [AFHTTPRequestSerializer serializer];
[manager.requestSerializer setValue:authToken forHTTPHeaderField:@"X-Auth-Token"];
[manager PUT:URL.absoluteString parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
    NSHTTPURLResponse *response = ((NSHTTPURLResponse *)[task response]);
    NSDictionary *headers = [response allHeaderFields];
    NSLog(@"Header Dict:: %@",headers);
    if ([response statusCode] == 201) {
        //Successfully container created
    }else{
        //Some problem occure
    }

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    NSLog(@"Error:: %@", error.localizedDescription);
}];}

3) 最后使用 "Auth token" 和 "x-Storage-url" 以及波纹管代码

在容器中上传视频
-(void)uploadFileInContainer{
NSString *authUrl = @"https://sjc01.objectstorage.softlayer.net/v1/AUTH_695d079a-ead3-4045-b303-a1b123acdb3db";
//Get Video From Document Directory
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *videoFilePath = [documentsDirectory stringByAppendingFormat:@"/vid10.mp4"];

//Convert video url to NSData
NSData *videoData = [NSData dataWithContentsOfFile:videoFilePath options:NSDataReadingMappedIfSafe error:&error];
if (videoData != nil ) {

    if ([PMCommonClass isNetworkRechable]) {

        NSString *urlString = [NSString stringWithFormat:@"%@/Container5/Video4.mp4",authUrl];
        NSMutableURLRequest *request  = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"PUT" URLString:urlString parameters:nil error:nil];
        [request setValue:authToken forHTTPHeaderField:@"X-Auth-Token"];
        [request setValue:@"video/mp4" forHTTPHeaderField:@"Content-Type"];
        [request setValue:@"video/mp4" forHTTPHeaderField:@"Accept"];

        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
        AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:configuration];

        NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithRequest:request fromData:videoData progress:^(NSProgress * _Nonnull uploadProgress) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"UPLOAD Progress==>%f",uploadProgress.fractionCompleted*100);
            });
        } completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
            if (error) {
                NSLog(@"Error: %@", error.localizedDescription);
            } else {
                NSLog(@"Success: %@ %@", response, responseObject);
            }
        }];
        [uploadTask resume];
    }
}}

4) 然后使用相同的过程从 object 存储容器下载上传的 object。

-(void)getObject{
NSString *authUrl = @"https://sjc01.objectstorage.softlayer.net/v1/AUTH_695d079a-ead3-4045-b303-a1b123acdb3db";
NSString *authToken = @"AUTH_tk9eafc199756fabe8066f";
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/Container5/Video4.mp4",authURL]];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.requestSerializer =  [AFHTTPRequestSerializer serializer];
[manager.requestSerializer setValue:authToken forHTTPHeaderField:@"X-Auth-Token"];
[manager.requestSerializer setValue:@"video/mp4" forHTTPHeaderField:@"Content-Type"];
[manager.requestSerializer setValue:@"video/mp4" forHTTPHeaderField:@"Accept"];
[manager GET:URL.absoluteString parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {

    NSHTTPURLResponse *response = ((NSHTTPURLResponse *)[task response]);
    NSDictionary *headers = [response allHeaderFields];
    NSLog(@"Header Dict:: %@",headers);

    //NSLog(@"Response OBJ:: %@",responseObject);
    //UIImage *image = [UIImage imageWithData:responseObject];
    //NSLog(@"uiiamge %@",image);


    NSData *videoData = responseObject;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *tempPath = [documentsDirectory stringByAppendingFormat:@"/video1026.mp4"];
    BOOL success = [videoData writeToFile:tempPath atomically:NO];
    if (success) {
        NSLog(@"save Path is:: %@",tempPath);
    }

} failure:^(NSURLSessionTask *operation, NSError *error) {
    NSLog(@"Error:: %@", error.localizedDescription);
}];}

这是从软层 object 存储上传和下载视频的以下步骤。