0

我想在服务器上上传我的大图。
是否可以将它们分块转换并上传到服务器上?

这是我上传图片的代码我如何在块中发送图片?

NSDateFormatter* df = [[NSDateFormatter alloc]init];
    [df setDateFormat:@"MM/dd/yyyy"];
    NSString *result = [df stringFromDate:assetDate];

    NSTimeInterval timeInterval = [assetDate timeIntervalSince1970];
    ALAssetRepresentation *rep = [temp defaultRepresentation];
    CGImageRef iref = [rep fullResolutionImage];
    StrPath = [StrPath stringByAppendingFormat:@"%d.%@",(int)timeInterval,strImageType];
    //UIImage *image = [UIImage imageWithCGImage:[rep fullResolutionImage]];

    UIImage *image =[UIImage imageWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];
    //------------------ metadata -------------------------------------------------------
    NSDictionary *imageMetadata = [rep metadata];
    NSString *strOrt=[NSString stringWithFormat:@"%@",[imageMetadata valueForKey:@"Orientation"]];

    NSData *dataObj = nil;
    dataObj = UIImageJPEGRepresentation(image, 1.0);
    NSString* StrFileData = [Base64 encode:dataObj];
    NSString* strFileHash = [dataObj md5Test];

    NSMutableDictionary *DictRequest = [[NSMutableDictionary alloc]init];
    [DictRequest setObject:srtprefSessionId forKey:@"SessionId"];
    [DictRequest setObject:StrPath forKey:@"Path"];
    [DictRequest setValue:[NSNumber numberWithBool:isTrash] forKey:@"UploadDirectlyToTrashbin"];
    [DictRequest setObject:StrFileData forKey:@"FileData"];
    [DictRequest setObject:strFileHash forKey:@"FileHash"];
    [DictRequest setObject:result forKey:@"DateCreated"];

    BOOL isNULL = [self stringIsEmpty:strOrt];
    if(!isNULL)
    {
        //[DictRequest setObject:strOrt forKey:@"Orientation"];
    }


    NSString *jsonString = [DictRequest JSONRepresentation];
    NSString *strUrl=[NSString stringWithFormat:@"%@",FileUpload_URL];
    NSURL *url1=[NSURL URLWithString:strUrl];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url1];
    [request setTimeoutInterval:60.0];
    [request setHTTPMethod:@"POST"];
    NSData *postData = [jsonString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
    [request setHTTPBody:postData];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];


    if(theConnection)
        [self Set2Defaults];

    theConnection = [[NSURLConnection alloc]initWithRequest:request delegate:self];

    [SVProgressHUD dismiss];

    if(theConnection)
        webData = [NSMutableData data];
    else
        NSLog(@"Connection Failed !!!");
4

3 回答 3

0

将您的图像转换为 utf8 字符串将该字符串分块发送并连接并在服务器端转换为图像。

于 2012-12-26T13:53:04.570 回答
0

当您向服务器发送数据时,可能会丢失数据包。丢包的原因可能是抖动、带宽低、信道拥挤。尝试减小图像大小并将其作为整体发送,以便您可以在流通道中使用其原始编码数据字节检索它

于 2012-12-26T13:39:42.027 回答
0

使用转换将您的图像转换为数据,并将其异步发送到服务器上。

于 2012-12-26T14:00:15.937 回答