AsihttpRequest didfinishselector decompression error iOS - ios

Hi I am downloading an epub file from my server of size (100-200 MB)
epub file is basically a zip file with extension ".epub"
Code which I am using to download the file:
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:TempBookUrl]];
bookZipPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *tempStr = [bookZipPath stringByAppendingPathComponent:[NSString stringWithFormat:#"temp%#.epub",model.iD]];
NSString *str = [bookZipPath stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.epub",model.iD]];
[request setTemporaryFileDownloadPath:tempStr];
[request setDownloadDestinationPath:str];
[request setDidFinishSelector:#selector(processFile:)];
[request setDidFailSelector:#selector(requestWentWrong:)];
[request setDelegate:self];
[request setAllowResumeForFileDownloads:YES];
[request setShowAccurateProgress:YES];
[request setDownloadProgressDelegate:self];
[request setShouldContinueWhenAppEntersBackground:YES];
[request startAsynchronous];
After lots of downloading I get the error
saying that unable to decompress the file as file do not exist at the temporary path.
ERROR: Decompression of /Users/admin/Library/Application
Support/iPhone
Simulator/7.0/Applications/07322021-F878-41DA-A712-5C175C5252B6/Documents/temp27.epub
failed the file does not exist
I am using iOS 7

Related

How to use GData framework in iOS app to upload images to Picasa?

In my app, I have an imageView, I want to post the image to Picasa.
I got some suggestion to use GData Framwork. I downloaded it from
code.google.com/p/gdata-objectivec-client/downloads/list
But, when I add the .a file in my Build phases, it is displayed as red. I have tried all the method in SO, as well as other forums.
Is there any other way to upload image to Picasa.
Any help would be appreciated.
I don't have an app to test this with, but I've translated the php-curl solution from this SO question.
NSString *authCode = [NSString stringWithFormat:#"GoogleLogin auth=",#"ACCESS CODE FROM OAUTH2"];
NSString *userId = #"USER ID GOES HERE";
NSString *albumId = #"ALBUM ID GOES HERE";
NSString *albumUrl = [NSString stringWithFormat:#"https://picasaweb.google.com/data/feed/api/user/%#/albumid/%#",userId, albumId];
// To get the data from a PNG file
NSData *postData = UIImagePNGRepresentation([UIImage imageNamed:#"YOUR IMAGE"]);
// To get the data from a JPEG file
//NSData *postData = UIImageJPEGRepresentation([UIImage imageNamed:#"YOUR IMAGE"], 0.9f);
NSString *postLength = [NSString stringWithFormat:#"%d", [postData length]];
// Init and set fields of the URLRequest
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:#"POST"];
[request setURL:[NSURL URLWithString:[NSString stringWithString:albumUrl]]];
[request setValue:#"image/jpeg" forHTTPHeaderField:#"Content-Type"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"2" forHTTPHeaderField:#"GData-Version"];
[request setValue:authCode forHTTPHeaderField:#"Authorization"];
[request setHTTPBody:postData];
NSURLResponse* rep = nil;
NSError *err = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&rep error:&err];
if (data && !err) {
//Do something with the response
}
Hope this helps.

How to upload String and Image using ASIFormDataRequest?

I want to upload follow Log Strings along with UIImage,
HOw can I achieve such objective????
I can see to send only image , but i want to send image along with text data using this ASIFormDataRequest, using POST request type.
NSLog(#"data is here %#\n%#\n%#\n%#\n%#\n",deviceID, postID, name, message, picture);
UIImage *image= [UIImage imageNamed:#"profile_avatar.png"];
NSString *strURL = #"https://abc.abc.com/comments/create";
// ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:strURL]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:strURL]]; // Upload a file on disk
// NSString *filename1=[NSString stringWithFormat:#"friendship.jpg"];
UIImage *image1=image;
NSData *imageData1=UIImageJPEGRepresentation(image1, 1.0);
[request setData:imageData1 withFileName:#"filename" andContentType:#"image/png" forKey:#"avatar"];
[request setRequestMethod:#"POST"];
[request addRequestHeader:#"Authorization" value:[NSString stringWithFormat:#"Basic %#",[ASIHTTPRequest base64forData:[[NSString stringWithFormat:#"username123:pass123"] dataUsingEncoding:NSUTF8StringEncoding]]]];
[request setValidatesSecureCertificate:NO];
//[request appendPostData:body];
[request setDelegate:self];
[request setTimeOutSeconds:3.0];
request.shouldAttemptPersistentConnection = NO;
[request setDidFinishSelector:#selector(uploadRequestFinished:)];
[request setDidFailSelector:#selector(uploadRequestFailed:)];
[request startAsynchronous];
Thanks
There is one method available to send parameter as well
[request setPostValue:#"YourValue" forKey:#"YourKey"];

saving wikitext to the server in ipad application

I am trying to edit the wikitext of a page using a textView and save it on the server using mediawiki API as follows:
- (void)saveAction{
NSString *savedString = textView.text;
NSString *baseurl=[[NSUserDefaults standardUserDefaults] stringForKey:#"url_preference"];
NSString *page=[[baseurl stringByAppendingString:#"/api.php?**action=edit&title=Testedit&text=savedString&token=**"] stringByAppendingString:[MySingleton sharedSingleton].token];
NSData *data=[savedString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postlength=[NSString stringWithFormat:#"%d",[data length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:page]];
[request setHTTPMethod:#"POST"];
[request setValue:postlength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPBody:data];
NSError *error=nil;
NSURLResponse *response=nil;
NSData *result=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *HTMLString2 = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];
NSLog(#"%#", HTMLString2);
}
but I am getting an error : internal_api_error_MWException,
Exception Caught: Detected bug in an extension! Hook iaifAPIEditBeforeSave has invalid call signature; Parameter 1 to iaifAPIEditBeforeSave() expected to be a reference.
Searched about the error on google but I didn't find anything. Please suggest something.
That wiki appears to have an outdated Data Import Extension. Update/uninstall as required. A quick hack that should fix this particular error would be to replace function iaifAPIEditBeforeSave(&$editPage, $text, &$resultArr) with function iaifAPIEditBeforeSave($editPage, $text, &$resultArr) in extensions/DataImport/IAI/includes/IAI_GlobalFunctions.php, however I don't know what else could be outdated/broken there.

NSMutableURLRequest transform to ASIFormDataRequest

I have writen the fellowing code:
NSString *urlString = [NSString stringWithFormat:ADDRESS,action];
postStr = #"user_name=Thomas Tan&phone=01234567891&password=123456";
NSData *myRequestData = [NSData dataWithBytes:[postStr UTF8String] length:[postStr length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:#"POST"];
[request setHTTPBody: myRequestData];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSLog(#"%#",responseString);
it works well,but now I want to use asihttprequest framework,so how to change the above code,I have writen the code,but it can't get the correct result and just get the server error infomation.so what's the problem?
NSString *urlString = [NSString stringWithFormat:ADDRESS,action];
NSURL *url = [NSURL URLWithString:urlString];
ASIFormDataRequest *requeset = [ASIFormDataRequest requestWithURL:url];
[requeset setRequestMethod:#"POST"];
[requeset setPostValue:#"Thomas Tan" forKey:#"user_name"];
[requeset setPostValue:#"01234567891" forKey:#"phone"];
[requeset setPostValue:#"123456" forKey:#"password"];
[requeset startSynchronous];
NSError *error = [requeset error];
if (!error) {
NSString *re = [requeset responseString];
NSLog(#"%#",re);
}
NSLog(#"%#",error);
thank you in advance.
UPDATE:
NSString *urlString = [NSString stringWithFormat:ADDRESS,action];
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:#"POST"];
[request appendPostData:[#"user_name=Thomas Tan&phone=01234567891&password=123456" dataUsingEncoding:NSUTF8StringEncoding]];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
NSString *re = [request responseString];
NSLog(#"%#",re);
}
NSLog(#"%#",error);
I use the above code ,It also can't get the same result,and error is not nil.
Your ASIHTTP code is not doing the same thing as your NSURLConnection code.
ASIFormDataRequest will automatically:
set the Content-Type header to application/x-www-form-urlencoded
URL-encoded your parameters
That's usually exactly what you want, but if you're getting the correct behavior with your NSURLConnection code and incorrect with ASIHTTP, then you need to change to a custom ASIHTTP POST and use ASIHTTPRequest, not ASIHTTPFormDataRequest, and then manually set the Conten-type back to application/x-www-form-urlencoded:
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:#"POST"];
[request addRequestHeader:#"Content-Type" value:#"application/x-www-form-urlencoded"];
[request appendPostData:[#"user_name=Thomas Tan&phone=01234567891&password=123456" dataUsingEncoding:NSUTF8StringEncoding]];
Doing this, and inspecting exactly what was sent to the server using Wireshark, I can see that the POST data sent is still not quite identical (ASIHTTP on the left, NSURLConnection on the right):
But the content type, length, and actual data is identical.
At this point, I'd expect your server to return the same result.
If it still doesn't, you can edit the ASIhTTP request parameters to match.

Uploading .db file to server..disk image malformed?

Can some please help in understanding what is going wrong???
I will have upload my .db file to server using multipart/formdata request.
I'm using ASIFormdataRequest to form the request and i'm getting the response as success.But when I try to download the file I'm getting disk image malformed.
I'm pasting the code
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
NSString* path = [self FilePath];
NSData *dataBaseData = [NSData alloc];
dataBaseData = [NSData dataWithContentsOfFile:path];
NSLog(#"databaselength %d",dataBaseData.length);
NSString* authHeader = [self returnAuthHeader];
NSLog(#"Auth Header %#", authHeader);
[request addRequestHeader:#"Accept" value:#"application/xml"];
[request addRequestHeader:#"Authorization" value:authHeader];
[request addRequestHeader:#"Content-Type" value:#"multipart/form-data"];
// [request setFile:dataBaseData withFileName:#"sample.db" andContentType:#"multipart/form-data" forKey:#"filedata"];
[request addData:dataBaseData withFileName:#"sample.db" andContentType:#"application/octet-stream" forKey:#"filedata"];
[request setPostFormat:ASIMultipartFormDataPostFormat];
[request setDelegate:self];
NSLog(#"Request %#",request);
[request updateUploadProgress];
[request startAsynchronous];
Found why db got corrupted and gave Disk image malformed!!!!!!
Was reading the db in a file in one thread and inserting values to the tables in the db in another thread.So the integrity of the db was not maintained.

Resources