NSURLSession and stream upload in background

后端 未结 4 1639
遇见更好的自我
遇见更好的自我 2021-01-02 10:19

I have some problems with using NSURLSession to upload photos from Asset Library to the server.

At first NSURLSession doesn\'t support stre

4条回答
  •  别那么骄傲
    2021-01-02 10:58

    Convert to NSData and copy and write in app folder

    ALAsset *asset = [cameraRollUploadImages objectAtIndex:startCount];
    ALAssetRepresentation *representation = [asset defaultRepresentation];
    
    // create a buffer to hold the data for the asset's image
    uint8_t *buffer = (Byte *)malloc(representation.size);// copy the data from the asset into the buffer
    NSUInteger length = [representation getBytes:buffer 
                                      fromOffset:0 
                                          length:representation.size 
                                           error:nil];
    
    // convert the buffer into a NSData object, free the buffer after
    NSData *image = [[NSData alloc] initWithBytesNoCopy:buffer 
                                                 length:representation.size
                                           freeWhenDone:YES];
    

提交回复
热议问题