使用Parse.com上传视频 [英] Using Parse.com to upload a video

查看:95
本文介绍了使用Parse.com上传视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是解析的新手,正在尝试将视频保存并上传到云中.这是我正在使用的代码,但是在调用doneButtonAction时,它始终会出现错误.我认为问题在于将视频另存为文件时,但我不知道如何解决.预先谢谢-

I am new to parse and am trying to save and upload a video to the cloud. This is the code I am using, but it keep getting an error when the doneButtonAction is called. I believe the problem is when the video is being saved as a file, but I have no idea how to fix that. Thank you in advance -

- (void)imagePickerController:(UIImagePickerController *)picker      didFinishPickingMediaWithInfo:(NSDictionary *)info {

    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
    NSLog(@"%@", videoURL);


    if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (self.moviePath))
    {
        UISaveVideoAtPathToSavedPhotosAlbum (self.moviePath, nil, nil, nil);
    }

    [self shouldUploadVideo];
    [self doneButtonAction];
}

- (void)shouldUploadVideo {

    //Capturamos el NSUserdefault para grabar el evento
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *loadstring = [defaults objectForKey:@"Video"];
    NSLog(@"Working at first line");



    NSData *videoData = [NSData dataWithContentsOfURL:self.videoURL];
    NSLog(@"Working at second line");


    PFFile *videoFile = [PFFile fileWithData:videoData];
    NSLog(@"Working at third line");

    [self.videoFile saveInBackground];
    NSLog(@"Working at last line");

}

- (void)doneButtonAction {
    // Make sure there was no errors creating the image files
    if (!self.videoFile) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Couldn't save your photo"
                                                       message:nil
                                                       delegate:nil
                                              cancelButtonTitle:nil
                                              otherButtonTitles:@"Dismiss",nil];
        [alert show];
        return;
    }

    // Create a Photo object
    PFObject *video = [PFObject objectWithClassName:kPAPPhotoClassKey];
    [video setObject:[PFUser currentUser] forKey:kPAPPhotoUserKey];
    [video setObject:self.videoFile forKey:@"Video"];

    // Request a background execution task to allow us to finish uploading
    // the photo even if the app is sent to the background
    self.photoPostBackgroundTaskId = [[UIApplication sharedApplication]   beginBackgroundTaskWithExpirationHandler:^{
        [[UIApplication sharedApplication] endBackgroundTask:self.photoPostBackgroundTaskId];
    }];

    // Save the Photo PFObject
    [video saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            NSLog(@"Photo uploaded");

            // Add the photo to the local cache
            [[PAPCache sharedCache] setAttributesForPhoto:video likers:[NSArray array] commenters:[NSArray array] likedByCurrentUser:NO];

            // Send a notification. The main timeline will refresh itself when caught
            [[NSNotificationCenter defaultCenter] postNotificationName:PAPTabBarControllerDidFinishEditingPhotoNotification object:video];
        } else {
            NSLog(@"Photo failed to save: %@", error);
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Couldn't post your photo"
                                                            message:nil
                                                           delegate:nil
                                                  cancelButtonTitle:nil
                                                  otherButtonTitles:@"Dismiss",nil];
            [alert show];
        }

        // If we are currently in the background, suspend the app, otherwise
        // cancel request for background processing.
        [[UIApplication sharedApplication] endBackgroundTask:self.photoPostBackgroundTaskId];
    }];

    // Dismiss this screen
    [self.parentViewController dismissViewControllerAnimated:YES completion:nil];

}

推荐答案

内部

- (void)shouldUploadVideo {

您有:

PFFile *videoFile = [PFFile fileWithData:videoData];
NSLog(@"Working at third line");

[self.videoFile saveInBackground];
NSLog(@"Working at last line");

您正在尝试在后台上传 self.videoFile ,而不是 videoFile .

You are trying to upload self.videoFile in background - not videoFile.

这意味着 videoFile 不在后台上传PFFile.

This means that videoFile is not uploading the PFFile in the background.

更改

PFFile *videoFile = [PFFile fileWithData:videoData];

self.videoFile = [PFFile fileWithData:videoData];

这篇关于使用Parse.com上传视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆