0

我正在使用一个 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] 文件属性:(空)

2014-08-19 17:25:58.432 BoxSDKSampleApp[17252:1243051] 内容长度:0

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

4

0 回答 0