NSURLSession and stream upload in background

后端 未结 4 1661
遇见更好的自我
遇见更好的自我 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 11:05

    Right now, there is no way otherthan saving the picture to local file system or temp directory.

    Following code make sure your data won't be lost with exif tags. (ALAsset => NSData)

    ALAssetRepresentation *assetRepresentation = [(ALAsset *)assetBeingUploaded defaultRepresentation];
    uint8_t *buffer = (uint8_t *)malloc(sizeof(uint8_t)*[assetRepresentation size]);
    NSUInteger buffered = 0;
    if (buffer != NULL)
    buffered = [assetRepresentation getBytes:buffer fromOffset:0.0 length:assetRepresentation.size error:nil];
    self.imageBeingUploaded = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
    

    The upload task in background session doesn't support completion handler. We should go for.,

    - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromFile:(NSURL *)fileURL;  
    

    I doubt how do we get the response headers or body in case if we are using background session & uploadtask with request using file?

提交回复
热议问题