从iOS应用程序上载Box上的图像

时间:2014-08-19 12:15:45

标签: ios box-api boxapiv2

我正在使用iOS应用程序,我必须在Box Service上传图像。在我从NSBundle上传图像后进行身份验证过程后,上传成功。 当我从路径图像上传时上传但只创建了文件,没有上传任何数据 以下是我上传的方法:

-m(void)uploadimages:(UIImage*)image 
{
    BoxFileBlock fileBlock = ^(BoxFile *file)
    {
        [self fetchFolderItemsWithFolderID:self.folderID name:self.navigationController.title];

        dispatch_sync(dispatch_get_main_queue(), ^{
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"File Upload Successful" message:[NSString stringWithFormat:@"File has id: %@", file.modelID] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
        });
    };

    BoxAPIJSONFailureBlock failureBlock = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary)
    {
        BOXLog(@"status code: %li", (long)response.statusCode);
        BOXLog(@"upload response JSON: %@", JSONDictionary);
    };

    BoxFilesRequestBuilder *builder = [[BoxFilesRequestBuilder alloc] init];
    NSInteger randomNumber = arc4random() % 100;
    NSString *filename = [NSString stringWithFormat:@"PicBackMan-%ld.jpg",(long)randomNumber];
    builder.name = filename;
    builder.parentID = self.folderID;

    NSLog(@"builder.parentID  : %@",builder.parentID);

    NSArray *pathList = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                            NSUserDomainMask,
                                                            YES);

    path = [[pathList objectAtIndex:0] stringByAppendingPathComponent:@"image.jpg"];


    NSLog(@"Path o/p is %@",path);

    NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath: path];

    NSLog(@"inputStream DIRECT : %@",inputStream);


    NSError *error;

    NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error];

    if (!error) {
        if (fileAttributes != nil) {
           NSLog(@"File attributes found.");
        } else {
            NSLog(@"File attributes not found.");
        }
    } else {
        NSLog(@"%@", [error localizedDescription]);

    long long contentLength = [[fileAttributes objectForKey:NSFileSize] longLongValue];

    NSLog(@"fileAttributes  : %@",fileAttributes);
    NSLog(@"contentLength  : %lld",contentLength);
    [[BoxSDK sharedSDK].filesManager uploadFileWithInputStream:inputStream contentLength:contentLength MIMEType:nil requestBuilder:builder success:fileBlock failure:failureBlock progress:nil];
}

我正在获取输出,但我的文件没有上传数据,只有创建了名称的文件的图像。 我在日志中得到以下输出:

builder.parentID:2323165189

2014-08-19 17:25:58.431 BoxSDKSampleApp[17252:1243051] /Users/bettermac9/Library/Application Support/iPhone Simulator/7.1-64/Applications/30DFB367-599B-4F39-AD62-D27B1081FE99/Documents/image.jpg

2014-08-19 17:25:58.432 BoxSDKSampleApp [17252:1243051] inputStream DIRECT:< __ NSCFInputStream:0x7f8f7ae5db00>

2014-08-19 17:25:58.432 BoxSDKSampleApp [17252:1243051]无法完成操作。 (可可错误260。)

2014-08-19 17:25:58.432 BoxSDKSampleApp [17252:1243051] fileAttributes:(null)

2014-08-19 17:25:58.432 BoxSDKSampleApp [17252:1243051] contentLength:0

请帮帮我,据我所知,我认为从路径读取文件并发送到NSinputstream时我犯了任何错误。请帮帮我。 谢谢

0 个答案:

没有答案