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

変換を使用して画像をデータに変換し、これをサーバーに非同期で送信します。

于 2012-12-26T14:00:15.937 に答える
0

サーバーにデータを送信しているときに、データ パケットが失われる可能性があります。パケット損失の原因は、ジッター、低帯域幅、過密チャネルである可能性があります。画像サイズを小さくして全体を送信し、ストリーム チャネルで元のエンコードされたデータ バイトを取得できるようにします。

于 2012-12-26T13:39:42.027 に答える
0

画像をutf8文字列に変換し、その文字列をチャンクで送信し、サーバー側で連結して画像に変換します。

于 2012-12-26T13:53:04.570 に答える