GoogleDrive file download issue - ios

I am able to download file from GoogleDrive API.
Using the following code.
NSString *url = [NSString stringWithFormat:#"https://www.googleapis.com/drive/v3/files/%#?alt=media",
identifier];
GTMSessionFetcher *fetcher = [self.service.fetcherService fetcherWithURLString:url];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
if (error == nil) {
NSLog(#"Retrieved file content");
// Do something with data
UIImage *img = [UIImage imageWithData:data];
NSLog(#"%#", img);
} else {
NSLog(#"An error occurred: %#", error);
[self showErrorAlert:error];
}
}];
It was working fine.(Getting image from data)
Now its not able to compose image.
UIImage *img = [UIImage imageWithData:data];
NSLog(#"%#", img);
Its giving Null.

Related

SDImageCache unable to retrieve the saved images in Cache

I'm using SDWebImage to store the images in cache and disk memory using a key but while querying using that key i am not getting the images, the code is
SDImageCache *imageCache = [[SDImageCache alloc] initWithNamespace:#"ImageCacheFolder"];
[imageCache queryCacheOperationForKey:[entryidarray objectAtIndex:indexpath.row] done:^(UIImage *image, NSData *data, SDImageCacheType cacheType) {
if (image) {
NSLog(#"image get from cache");
[imageview setImage:image];
} else {
[imageview sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:[UIImage imageNamed:#"PlaceholderImage-Day"] options:SDWebImageProgressiveDownload];
}
}];
NSURL *url = [NSURL URLWithString:imgStr];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
if (img) {
NSLog(#"the image is not nil");
[[SDImageCache sharedImageCache] storeImage:img forKey:[entryidarray objectAtIndex:indexpath.row] toDisk:YES completion:nil];
}else {
NSLog(#"the image is nil");
}
Try this
.
if (img) {
NSLog(#"the image is not nil");
[imageCache storeImage:img forKey:[entryidarray objectAtIndex:indexpath.row] toDisk:YES completion:nil];
}else {
NSLog(#"the image is nil");
}

How to Update a file to the Content module in QuickBlox iOS

After uploading image in content module how to update image?
i'm below code to upload file code
// Upload a file to the Content module
NSData *imageData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"image45" ofType:#"png"]];
[QBRequest TUploadFile:imageData fileName:#"arrow.png" contentType:#"image/png" isPublic:NO successBlock:^(QBResponse *response, QBCBlob *uploadedBlob) {
// set dialog's photo
NSUInteger uploadedFileID = uploadedBlob.ID;
dialog.photo = [NSString stringWithFormat:#"%d", uploadedFileID];
} statusBlock:^(QBRequest *request, QBRequestStatus *status) {
// handle progress
} errorBlock:^(QBResponse *response) {
NSLog(#"error: %#", response.error);
}];
Find This code for update content file
NSData *file = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"plus" ofType:#"png"]];
QBCBlob *blob = [QBCBlob blob];
blob.ID = 65268; // ID of exists file
blob.name = #"Plus";
[QBRequest TUpdateFileWithData:file file:blob successBlock:^(QBResponse *response) {
// File updated
// if blob.isPublic == YES
NSString *url = [blob publicUrl];
} statusBlock:^(QBRequest *request, QBRequestStatus *status) {
// handle progress
} errorBlock:^(QBResponse *response) {
NSLog(#"error: %#", response.error);
}];

downloading video from youtube objective c

I'm trying to download video from youtube but getting error.
Error mention in code
my code
-(void)downloadVideo{
LBYouTubeExtractor *extractor = [[LBYouTubeExtractor alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:(#"https://www.youtube.com/watch?v=%#"), videoIdToDownload ]] quality:LBYouTubeVideoQualityLarge];
[extractor extractVideoURLWithCompletionBlock:^(NSURL *videoURL, NSError *error) {
if(!error) {
NSLog(#"Did extract video URL using completion block: %#", videoURL);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSError* error = nil;
NSData* data1 = [NSData dataWithContentsOfURL:videoURL options:NSDataReadingUncached error:&error]; //data1 is nill
if (error) { //Error Domain=NSCocoaErrorDomain Code=256 "The file “3gpp;+codecs="mp4v.20.3,+mp4a.40.2"&fallback_host=tc.v8.cache4.googlevideo.com&itag=36” couldn’t be opened."
NSLog(#"error=%#", error);
}else{
NSString *filename = [NSString stringWithFormat:(#"video_%#.mp4"), videoIdToDownload ];
[data1 writeToFile:[dirPath stringByAppendingPathComponent:filename] atomically:YES];
NSLog(#"File %# successfully saved", filename);
}
});
} else {
NSLog(#"Failed extracting video URL using block due to error:%#", error);
}
}];
}
using this lib
https://github.com/larcus94/LBYouTubeView
If anyone now solution please help me.
Thanks

Cropping an image before sending to the server on iOS

I'm trying to crop an image before sending to the server and I'm having issues.
I'm was trying to do this:
imageUploadReq.photo = [self encodeToBase64String:[UIImage imageWithData:UIImageJPEGRepresentation(fileData, 0.07f)]];
But Xcode is complaining that "Incompatible pointer types passing NSData * to parameter type UIImage". I tried to cast it, but it wouldn't work either.
Here is the code:
- (void)uploadPhoto {
NSData *fileData;
if (self.image != nil) {
UIImage *newImage = [self resizeImage:self.image toWidth:320.0f andHeight:480.0f];
fileData = UIImageJPEGRepresentation(newImage, 0.07f);
}
WUTModelImageUploadReq *imageUploadReq = [[WUTModelImageUploadReq alloc]init];
// I'm trying to set the first parameter of UIImageJPEGRepresentation to fileData
imageUploadReq.photo = [self encodeToBase64String:[UIImage imageWithData:UIImageJPEGRepresentation(self.viewControllerPost.imageForPost, 0.07f)]];
imageUploadReq.extension = #"jpg";
void (^wsSuccessHandler)(AFHTTPRequestOperation *operation, NSDictionary* responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject){
NSLog(#"Pull Feed responseObject %#",responseObject);
NSError *error;
WUTModelPostImageResponse *wsResponse = [[WUTModelPostImageResponse alloc]initWithDictionary:(NSDictionary *)responseObject error:&error];
if (error) {
errorMessage = #"Failure to upload image.";
[self postExecuteFail];
}else{
if (wsResponse.success) {
WUTModelImage *imageTemp = [wsResponse.data firstObject];
[postItem setObject:imageTemp.photo forKey:#"photo"];
[self uploadPostFeed];
}else{
errorMessage = #"Failure to upload image.";
[self postExecuteFail];
}
}
};
void (^wsErrorHandler)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error){
if ([error.localizedDescription rangeOfString:#"401"].location != NSNotFound)
errorMessage = #"It seems that your login session get expire, Please relogin after logged out.";
else
errorMessage = #"Failure to upload image.";
[self postExecuteFail];
};
AFHTTPRequestOperation *op = [WUTCommonWebServices WebServicePostCallWithAccessTokenForEndPoint:WS_UploadImage WithJson:imageUploadReq ForSuccess:wsSuccessHandler ForFailure:wsErrorHandler];
[op start];
}
I think, you need this:
+(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage; }
You just need to pass original image and your desired size and it will return your expected image.
Call the method like:
UIImage *originalImage = [info valueForKey:UIImagePickerControllerOriginalImage]; // here originalImage is image taken from camera or you can use whatever you want
UIImage * image = [GlobalFunction imageWithImage:originalImage scaledToSize:CGSizeMake(200, 200)]; // GlobalFunction is class where I have defined this method and it returns UIImage of size (200, 200)

Can we upload photos in Adobe Assets using Abode Creative SDK for iOS and Android?

Using this chunk of code only for accessing the Adobe files in my iOS project, but how can I upload my pictures in Adobe Assets cloud and save it.
[[AdobeUXAssetBrowser sharedBrowser]popupFileBrowser:^(AdobeSelectionAssetArray *itemSelections) {
NSLog(#"Selected a file");
for(id item in itemSelections) {
AdobeAsset *it = ((AdobeSelectionAsset *)item).selectedItem;
NSLog(#"File name %#", it.name);
[_statuslabel setText:fileDesc];
//If an image, let's draw it locally
NSString *fileType = ((AdobeAssetFile *)it).type;
if([fileType isEqualToString:#"image/jpeg" ] || [fileType isEqualToString:#"image/png" ]) {
NSLog(#"Going to download the image");
[((AdobeAssetFile *)it) getData:NSOperationQueuePriorityHigh
onProgress:^(double fractionCompleted) {
}
onCompletion:^(NSData *data, BOOL fromcache) {
NSLog(#"Done downloaded");
UIImage *preview = [UIImage imageWithData:data];
}
onCancellation:^(void){
}
onError:^(NSError *error) {
}
];
}
}
} onError:^(NSError *error)
{
//do nothing
NSLog(#"Error");
}];
You can find a tutorial on how to upload and download files from Creative Cloud using the CreativeSDK here:
https://creativesdk.adobe.com/docs/ios/#/articles/files/index.html
The code in particular that deals with file uploads is below:
NSData *imgData = UIImageJPEGRepresentation( yourImage, 0.8f );
NSString *dataPath = [NSTemporaryDirectory() stringByAppendingPathComponent:#"foo.jpg"];
NSURL *dataURL = [NSURL fileURLWithPath:dataPath];
NSError *err;
BOOL success = [imgData writeToFile:dataPath options:NSDataWritingAtomic error:&err];
if (success) {
AdobeAssetFolder *root = [AdobeAssetFolder getRootOrderedByField:AdobeAssetFolderOrderByName orderDirection:AdobeAssetFolderOrderDescending];
[AdobeAssetFile create:#"foo.jpg"
inFolder:root
withDataPath:dataURL
withType:kMimeTypeJPEG
withCollisionPolicy:AdobeAssetFileCollisionPolicyAppendUniqueNumber
onProgress:^(double fractionCompleted) {
NSLog(#"Percent complete %f", fractionCompleted);
}
onCompletion:^(AdobeAssetFile *file) {
NSLog(#"Uploaded");
}
onCancellation:nil
onError:^(NSError *error) {
NSLog(#"error uploading %#", error);
}];
}

Resources