How to get image from NSOutputStream in Objective-C
Asked Answered
S

0

0

I am using twilio chat SDK, in that I am doing store and retrieve the image. So to retrieve the image from twilio I am getting NSOutputStream, And I don't know that how to convert NSOutputStream to image. Please see the below code which provided by twilio and give me some suggestions.

chatCell.message = message.body;
if (message.hasMedia) {
    NSLog(@"mediaFilename: %@ (optional)", message.mediaFilename);
    NSLog(@"mediaSize: %lu", (unsigned long)message.mediaSize);
    // Set up output stream for media content
    NSString *tempFilename = [NSTemporaryDirectory() stringByAppendingPathComponent:message.mediaFilename ? @"file.dat" : message.mediaFilename];
    NSOutputStream *outputStream = [NSOutputStream outputStreamToFileAtPath:tempFilename append:NO];

    // Request the start of the download
    [message getMediaWithOutputStream:outputStream
                            onStarted:^{
                                // Called when download of media begins.
                            } onProgress:^(NSUInteger bytes) {
                                // Called as download progresses, with the current byte count.
                            } onCompleted:^(NSString * _Nonnull mediaSid) {
                                // Called when download is completed, with the new mediaSid if successful.
                                // Full failure details will be provided through the completion block below.
                            } completion:^(TCHResult * _Nonnull result) {
                                if (!result.isSuccessful) {
                                    NSLog(@"Download failed: %@", result.error);
                                } else {
                                    NSLog(@"Download successful");
                                    NSLog(@"%@",message.body);
                                }
                            }];
}   

I am not sure how to get an image after download complete successful. Please help me to fix this.

Thanks in advance.

Shallot answered 30/12, 2019 at 6:16 Comment(2)
Check this? github.com/twilio/twilio-chat-demo-ios/blob/master/Demo-ObjC/… ? You get the image at [UIImage imageWithContentsOfFile:finalFilename].Tolidine
@Tolidine Thank You So So much man. You are a saviour :)Shallot

© 2022 - 2024 — McMap. All rights reserved.