ALAsset , send a photo to a web service including its exif data

前端 未结 1 1664
借酒劲吻你
借酒劲吻你 2021-01-06 10:36

I want to send a photo from the camera roll to a web services - including its exif data. Im using ASIFormDataRequest - so I do :

ASIFormDataRequest *request         


        
1条回答
  •  醉话见心
    2021-01-06 11:25

    ok - i think i figured it out. The trick is to go with the defaultRepresentaion's raw data:

    ALAsset* selectedAsset = [assets objectAtIndex:index];
    
    int byteArraySize = selectedAsset.defaultRepresentation.size;
    
    NSMutableData* rawData = [[NSMutableData alloc]initWithCapacity:byteArraySize];
    void* bufferPointer = [rawData mutableBytes];
    
    NSError* error=nil;
    [selectedAsset.defaultRepresentation getBytes:bufferPointer fromOffset:0 length:byteArraySize error:&error];
    if (error) {
        NSLog(@"%@",error);
    }
    rawData = [NSMutableData dataWithBytes:bufferPointer length:byteArraySize];
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
    NSString *cachesDirectory = [paths objectAtIndex:0];
    NSString* filePath = [NSString stringWithFormat:@"%@/imageTemp.png",cachesDirectory];
    [rawData writeToFile:filePath atomically:YES];
    

    After using the path to send the image to the server the file on the server keeps all the exif data

    0 讨论(0)
提交回复
热议问题