Unknown error when uploading file to ftp server - ios

I am trying to upload an image file to the server. I am applying the example from https://github.com/valentinradu/WhiteRaccoon
Here is the code:
UIImage *image = [UIImage imageNamed:#"hotel1.jpg"];
NSData *imageData = UIImageJPEGRepresentation(image, 0);
WRRequestUpload * uploadImage = [[WRRequestUpload alloc] init];
uploadImage.delegate = (id)self;
//for anonymous login just leave the username and password nil
uploadImage.hostname = #"***.***.***.***";
uploadImage.username = #"-------";
uploadImage.password = #"-------";
//we set our data
uploadImage.sentData = imageData;
//the path needs to be absolute to the FTP root folder.
//full URL would be ftp://xxx.xxx.xxx.xxx/space.jpg
uploadImage.path = #"/android_images/image.jpg";
//we start the request
[uploadImage start];
but it gives error -[WRRequestListDirectory stream:handleEvent:] [Line 1004] Unknown error!
am I missing anything. Please help me out.

in the uploadimage.hostname property try skipping the ftp:// part and enter the host address alone for eg: "qwerty.com" instead of "ftp://qwerty.com" , it solved for me, and make sure that the authentication details given are correct. cheers !!

if you are using BlackRaccoon,
Please make one line change in BRRequest.m file.
In - (id)initWithDelegate:(id<BRRequestDelegate>)aDelegate Function.
Change
self.passiveMode = YES;
to
self.passiveMode = NO;
And it will work....
That change worked for me.

Related

HERE API always respose NMARoutingErrorInvalidOperation

I use the following function to get the optimal route.
https://wse.ls.hereapi.com/2/findsequence.json?start=25.082621,121.583021&destination1=25.097258,121.517384&destination2=25.041825,121.514988&destination3=25.026060,121.527532&destination4=25.034607,121.488616&destination5=25.063467,121.539141&destination6=25.070833,121.531389&destination7=25.023056,121.505278&destination8=25.093102,121.532366&destination9=25.094807,121.529036&destination10=25.075230,121.560761&destination11=25.093102,121.532366&destination12=25.118899,121.470798&mode=fastest;car&&apiKey=...
And try to use this (HERE SDK FOR IOS (PREMIUM EDITION) V3.17) :
NMARoutingMode *routingMode = [[NMARoutingMode alloc] initWithRoutingType:NMARoutingTypeFastest transportMode:NMATransportModeScooter routingOptions:NMARoutingOptionAvoidHighway];
NMACoreRouter *coreRouter = [[NMACoreRouter alloc] init];
coreRouter.connectivity = NMACoreRouterConnectivityOnline;
[coreRouter calculateRouteWithStops:stops routingMode:routingMode completionBlock:^(NMARouteResult * _Nullable routeResult, NMARoutingError error) {
}];
to bring out NMARouteResult, but it only respond NMARoutingErrorInvalidOperation
How do I solve the problem?
The error indicates that another request is already being processed. Please make sure you are not calling the route calculation until the result of the previous request is returned.

TransloadIt image upload issue when image is too small in size in ios

While uploading the image of too small size e.g when i crop the image Transloadit server always reply with this response.
{"error":"FILE_FILTER_DECLINED_FILE","message":"One of your files was declined","reason":"file_0"}
I also tried testing response by adding STEP in the ASSEMBLY with force_accept parameter considering(hoping) that it will accept any file size. But still getting the same response.
Here is the code snippet :
Transloadit *transloadit = [[Transloadit alloc]init:TRANSLOADIT_API_KEY];
AssemblyBuilder *assembly = [[AssemblyBuilder alloc]init];
[assembly setTemplateID:TRANSLOADIT_TEMPLATE_ID];
NSData *imgData = UIImageJPEGRepresentation(imageToUpload, 1.0f);
NSError* error;
//Add a file to be uploaded with autogenerated key
[assembly addFile:imgData withError:error];
if(error!=nil)
TRANSLOADIT_LOG_ERROR(self.class,error);
NSObject<IStep>* step=[[Step alloc] init];
[step setOptionKey:#"robot" object:#"/image/resize"];
[step setOptionKey:#"width" object:#(75)];
[step setOptionKey:#"height" object:#(75)];
[step setOptionKey:#"resize_strategy" object:#"pad"];
[step setOptionKey:#"background" object:#"#000000"];
[step setOptionKey:#"force_accept" object:[NSNumber numberWithBool:YES]];
//Add the step to the assembly
[assembly addStepName:#"thumb" step:step];
//Invoke assembly, and wait for the result
TransloaditResponse* response =[transloadit invokeAssembly:assembly withError:error];
if(error!=nil)
{
TRANSLOADIT_LOG_ERROR_WITH_MESSAGE(self.class,#"Error has occured while completing assembly");
}
if([response isSuccess])
{
// success code
}
else
{
// failure code
}
If someone can help me. Thanks :)
This error can only surface if you use the file/filter robot to restrict what files can be uploaded. While I don't see you using it in your code, it might very well be used inside the saved template instructions you're referencing by TRANSLOADIT_TEMPLATE_ID

Can i change the server url with sudzc?

I am trying to generate source code from a wsdl file for iOS. I've stumbled upon a couple of tools and so far wsclient++ and sudzc at least seem to work. But I need to send requests to different servers with the same soap interface, depending on the state of the iOS app.
In the source code generated by wsclient I can set the server URL via
MyWebService* ws = [MyWebService service];
// // set base url for entire application
[SoapWebService setGlobalBaseUrl: #"http://domain.com"];
NSError* error = nil;
Result* rs = [ws callMethod: p1 param2:p2 error:&error];
Which would me allow me to do something like
if(condition1) [SoapWebService setGlobalBaseUrl: #"http://betaserver.com"];
if(condition2) [SoapWebService setGlobalBaseUrl: #"http://developserver.com"];
if(condition3) [SoapWebService setGlobalBaseUrl: #"http://liveserver.com"];
Is there a way to archive something similar with the source code generated by sudzc?
As long as the soap is the same response you shouldn't have a problem using your code. There is a file that stores the server address. The code generated by sudzc can be modified to any address. I actually created a dynamic way of hitting servers. I will find the file and code I used to do this.
You can search the project for your domain you used for sudzc.
I'm not in front of a mac right now, but I will update later.
UPDATE:
Ok, so I created a settings tab and allowed the user to input a specific ip address if necessary. It saves the IP address in a dictionary and then this file retrieves it from the dictionary. I left some of my original comments and added some in the code so you can see both ways. If it confuses you let me know and I'll edit again. In my sudzc generated code I modified the file to this:
/*
wsUpdateQOH.m
The implementation classes and methods for the wsUpdateQOH web service.
Generated by SudzC.com
*/
#import "wsUpdateQOH.h"
#import "Soap.h"
#import "Settings.h"
#define URL #"http://%#/webServiceAddress/updateqoh.asmx"
/* Implementation of the service */
#implementation wsUpdateQOH
- (id) init
{
if(self = [super init])
{
// take out hard coded address and add variable to have a dynamic IP #"http://www.site.com/webServiceAddress/updateqoh.asmx"
// here is the dictionary return and format of the url string
NSString *savedValue = [[NSUserDefaults standardUserDefaults] stringForKey:#"serverIP"];
self.serviceUrl = [[NSString alloc] initWithFormat:URL, savedValue];
// uncomment for a hard coded address self.serviceUrl = #"http://%#/webServiceAddress/updateqoh.asmx";
self.namespace = #"http://tempuri.org/webServiceAddress/UpdateQOH";
self.headers = nil;
self.logging = NO;
}
return self;
}
- (id) initWithUsername: (NSString*) username andPassword: (NSString*) password {
if(self = [super initWithUsername:username andPassword:password]) {
}
return self;
}
+ (wsUpdateQOH*) service {
return [wsUpdateQOH serviceWithUsername:nil andPassword:nil];
}
+ (wsUpdateQOH*) serviceWithUsername: (NSString*) username andPassword: (NSString*) password {
return [[[wsUpdateQOH alloc] initWithUsername:username andPassword:password] autorelease];
}
// *** Below here is the soap actions ***

Saving an image to Parse through the REST API, then using it in iOS app

I am developing an application where users are meant to store images on Parse through a web interface. Those images can be then displayed in a native iOS app.
Images are uploaded to Parse through Parse REST API; the URL of the stored image is then saved as a string property of a PFObject. This is the javascript code I use to this aim:
function postImageToParse(fileName, file, onSuccess, onError) {
file = file.replace(/^data:image\/(png|jpeg|jpg);base64,/, "");
var binaryImg = atob(file);
var length = binaryImg.length;
var ab = new ArrayBuffer(length);
var ua = new Uint8Array(ab);
for (var i = 0; i < length; i++) {
ua[i] = binaryImg.charCodeAt(i);
}
var blob = new Blob([ab],{type:"image/jpeg"});
var serverUrl = 'https://api.parse.com/1/files/' + basename(fileName);
$.ajax({
type: "POST",
beforeSend: function(request) {
request.setRequestHeader("X-Parse-Application-Id", '...');
request.setRequestHeader("X-Parse-REST-API-Key", '...');
request.setRequestHeader("Content-Type", file.type);
},
url: serverUrl,
data: blob,
processData: false,
contentType: false,
success:onSuccess,
error:onError
});
}
This is working correctly and I get back a URL of the form:
http://files.parse.com/b6a8c6d1-ba52-4d82-bde7-d2f2c9bb6fe4/6279b03f-521a-4481-97ae-553a0396ff98-xyz
Now, I have tried to use PFImageView on iOS to retrieve/display the image, as explained here, but found myself unable to create a PFFile to pass as a file property to the PFImageView object as required by this snippet:
PFImageView *creature = [[PFImageView alloc] init];
creature.image = [UIImage imageNamed:#"1.jpg"]; // placeholder image
creature.file = (PFFile*)file;
[creature loadInBackground];
Of course, I can download the image by directly accessing the URL to it that I have stored in my PFObject, but I am wondering if this is correct and if there are better ways to handle this.
So, in the described scenario, how should I get an image stored on Parse for which I have the URL returned by the REST API call used to upload it?
I looked up the interface of PFFile and I didn't find a way of downloading a PFFile directly. However, you said that you set the URL of the file as a string property of PFObject. Instead, why don't you set that property as a PFFile?
PFObject *object = ....
PFFile *imageFile = [object objectForKey:#"imageFile"];
creature.file = file;
I ended up asking the same question on the parse.com forum and got an useful answer.
It seems that a supported way of managing an image uploaded via the Parse REST API is associating the image to a previously created object through another REST call. Doing this would allow to use later PFFile on the iOS side.

Get data from webserver (php/mysql) by ASIHTTPRequest JSON

I am sending reguest to webserver in this function:
-(void)getData
{
NSURL *url = [NSURL URLWithString:#"http://10.10.10.10/application.php"]; //some address
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
request.delegate = self;
[request setPostValue:#"6577098" forKey:#"serial_number"];
[request startAsynchronous];
}
Then on server part in application.php :
<?php
//$serial_number from $_POST["serial_number"];
$serial_number = $this->getString('serial_number', 64);
$stmt = $this->pdo->prepare('SELECT S.DateTime, SN.Name FROM States S LEFT JOIN StateNames SN on SN.ID=S.State_ID WHERE S.SerialNumber = ?');
$stmt->execute(array($serial_number));
$states = $stmt->fetchAll(PDO::FETCH_ASSOC);
$result = array();
foreach ($states as $state)
{
$result[] = $state;
}
sendResponse(200, json_encode($result));
?>
This part works when I try it from browser, it works and I get this:
[{"DateTime":"2013-05-15 10:22:11","Name":"No water"},{"DateTime":"2013-05-13 14:55:31","Name":"Water"}]
Then back to process it in Xcode:
-(void)requestFinished:(ASIHTTPRequest *)request
{
if (request.responseStatusCode == 200)
{
NSString *responseString = [request responseString];
NSLog(#"%#",responseString); //if I try this nothing happened
}
}
I think I have to do something with JSON.
I thing I have bad response on my request. But I have responceStatusCode 200.
Can anyone help me? I didn't find what's wrong.
Thanks
I would need specifics to tell you what server settings you need to adjust. My next best advice - debug line by line. For example in php file, do:
$serial_number = $this->getString('serial_number', 64); //there I get serial_number from $_POST["serial_number"];
echo $serial_number; die;
// ...
at this point if you run your app again, you should see the serial # printed in -(void)requestFinished:(ASIHTTPRequest *)request, if nothing breaks up to here. If you do see it, remove echo and die, move on
//...
$stmt = $this->pdo->prepare('SELECT S.DateTime, SN.Name FROM States S LEFT JOIN StateNames SN on SN.ID=S.State_ID WHERE S.SerialNumber = ?');
$stmt->execute(array($serial_number));
$states = $stmt->fetchAll(PDO::FETCH_ASSOC);
print_r($states); die;
// ...
if no responce there, this might mean that you don't have PDO driver installed with your php.
If the next line sendResponse(200, json_encode($result)); breaks it, then my guess is that your php installation lacks json module.

Resources