[aerogear-dev] File Upload

Marc Pires marcpiresrj at gmail.com
Tue Nov 18 08:26:45 EST 2014


Hi Guys, well, i'm developing an app that uses the 1.6 version  of
AeroGear. Everything is going very with except that i could not get an
image (from a UIImageView) upload to work.

Here what i'm doing.

1) Get a user photo from camera ou library
2) Issue a save request to the api endpoint.

The problem i'm having is that i get the following error:

*The operation couldn’t be completed. (NSURLErrorDomain error -1001.)"
UserInfo=0x79f01e00 {NSErrorFailingURLKey=http://<Server
IP>/service/test/uploadios, NSErrorFailingURLStringKey=http://**http://<Server
IP>/service/test/uploadios**, NSUnderlyingError=0x79fd9020 "The operation
couldn’t be completed. (kCFErrorDomainCFNetwork error -1001.*


Below is the code i'm using from this:

-(void)performPhotoUpload

{

   NSString *webservicePref = [[NSUserDefaults standardUserDefaults]
stringForKey:@"serviceUrlSetting"];



    NSURL *projectsURL = [NSURL URLWithString:webservicePref];



    id<AGPipe> registrationPipe;



    AGPipeline *pipeline = [AGPipeline pipelineWithBaseURL:projectsURL];



    registrationPipe = [pipeline pipe:^(id<AGPipeConfig> config) {



        [config setName:@"/service/test/uploadios"];

        [config setType:@"REST"];



    }];





    [registrationPipe save:[self extractMultiPartData]

                   success:^(id responseObject)

     {

         NSLog(@"Returned Object:%@", responseObject);



     }

     failure:^(NSError *error)

     {



         NSLog(@"Error:%@",[error description]);



     }];



-(NSDictionary *)extractMultiPartData

{

    NSString *filename = self.patientPhoto.accessibilityIdentifier;



    //Check if an image was assigned for user

    [self hasPhoto:filename];



    NSData *imageData = UIImageJPEGRepresentation(self.patientPhoto.image,
0.2);



    AGFileDataPart *dataPart = [[AGFileDataPart alloc]
initWithFileData:imageData
                                                                name:
@"image"

                                                                   fileName
:filename

                                                                   mimeType:
@"application/octet-stream"];





    NSDictionary *imgDict = @{@"data": dataPart};



    return imgDict;

-- 
Desenvolvedor IOS, Rails, RIA

http://www.linkedin.com/in/marcpires
http://about.me/marcelo_pires
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/aerogear-dev/attachments/20141118/31994d34/attachment.html 


More information about the aerogear-dev mailing list