cancel
Showing results for 
Search instead for 
Did you mean: 

Uploading a image file from iOS to Server using sup 2.1.3 (supBigbinary)

0 Kudos

Hi All,

     I am currently developing an application which uploads document on the backend from iOS through SUP. I am using SUPBigBinary  format for the same. I am currently on SUP 2.1.3. The code that I am using is as follows:

NSData *data = UIImageJPEGRepresentation([UIImage imageNamed:@"select.png"],  0.0);

SUPBigBinary *img = nil;

[img openForWrite:[data length]];

[img write: data];

[img close];

When I put NSLog for data i get memory addresses for the Binary but, for SUPBigBinary I am getting (null) also, when I use create method and push data to back-end i get value in BigBinary as "0x".

According to me, Back-end part will come later in the picture, main issue is NSData is not getting transferred to SUPBigBinary [i.e. from data to img].

Please help me out in this, it's real urgent.

Thanks in advance.

Regards,

Saurabh

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Ivan & Sujith,

     Thanks for your help. I have solved the issue with SUPBigBinary... There is issue with memory allocation which is solved It is very much possible to work with BigBinary. Thank you sujith for Odata way It's something very new and very helpful.

Thank you & Regards,

saurabh

sujith_prathap
Advisor
Advisor
0 Kudos

Glad you found it useful

rakshit_doshi
Active Contributor
0 Kudos

Hi,

Even i am getting the same error at openforWrite:

How did you solve it.

Thanks,

Former Member
0 Kudos

Hi.. saurbh kerkar ,

i am also facing the problem while posting image to the sup sever..

I have tried like following:

  UIImage *img34 =[UIImage imageNamed:@"user.png"];

    NSData *tempData34 = UIImagePNGRepresentation(img34);

@try {


       

        SUP111Product *newData = [SUP111Product getInstance];

        newData.id_ = 502;

        newData.name =@"anil";

        newData.description_ =@"GGGG";

        newData.prod_size =@"MM";

        newData.color =@"red";

        int32_t qty = 2;

        newData.quantity = qty;

        NSNumber *aShort = [NSNumber numberWithShort:32];

        newData.unit_price =aShort;

        newData.picture_name =@"man.png";

        SUPBigBinary *text  =[SUPBigBinary getInstance];     //here i am getting error

        [text openForWrite:[tempData34 length]];

        [text write:tempData34];

        newData.catalog_picture = text;

        [text close];

        [newData save];

        [newData submitPending];

        [SUP111SUP111DB synchronize];

       

       

       

    }

    @catch (NSException *exception) {

    

        NSLog(@"exce: %@",[exception description]);

    }

  

can you help me how to post image to sup server in iOS?

can you post any sample code what you did to post image to sup server?

Thanks in Advance....

Answers (3)

Answers (3)

sujith_prathap
Advisor
Advisor
0 Kudos

Hi Saurabh,

                    For 2.1.3 you can use SUPRequest instead of ODP request and it should work.

Best Regards,

Sujith

sujith_prathap
Advisor
Advisor
0 Kudos

Hi Saurabh,

                    Below is the method i use to upload images to SUP. I do not do an initialization at all and it works fine.

You should try doing this. Another question i would like to ask is:

What is the size of the image that you are uploading?

I think i read somewhere that 2.1.3 does not support streaming. SO it just might be the case that the image is too big and hence the problem. But this is just speculation.

Best Regards,

Sujith

-(IBAction)uploadStart:(id)sender

{

    NSDate *uploadTimer = [NSDate date];

    [imageView1 removeFromSuperview];

   

    UIImage *image;

    NSData *postData;

    NSLog(@"Upload Started");

    if(flag)

    {

        image = [UIImage imageNamed:@"The-Dark-Knight.jpg"];

        postData = UIImageJPEGRepresentation (image,CGFLOAT_MIN);

        flag = NO;   

    }

    else

    {

        image = [UIImage imageNamed:@"witcher2.png"];

        postData = UIImagePNGRepresentation(image);

        flag = YES;

       

    }

   

    ODPRequest *postRequest2 = [ODPRequest requestWithURL:[NSURL URLWithString:@"http://ldcig8p.wdf.sap.corp:50018/sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection('LH')/$value"]];

    [postRequest2 setRequestMethod:@"PUT"];

    [postRequest2 addRequestHeader:@"Content-Type" value:@"image/jpeg"];

    [postRequest2 addRequestHeader:@"X-Requested-With" value:@"XMLHttpRequest"];

    [postRequest2 setPostBody:[NSMutableData dataWithData:postData]];

    [postRequest2 setUsername:@"*******"];

    [postRequest2 setPassword:@"*******"];

    [postRequest2 startSynchronous];

   

    if (postRequest2.error) {

        NSLog(@"%@", [postRequest2.error localizedDescription]);

    }

    else

    {

////        NSLog(@"Response String:   %@",[postRequest2 responseString]);

       

        float uploadTime = [uploadTimer timeIntervalSinceNow] * -1000.0;;

        NSLog(@"The total time for upload is %fms",uploadTime);

    }

   

   

}

0 Kudos

Hi Sujith,

     Thank you for the response.

I went through the code snippet you have forwarded but, if I am not wrong this works with SUP 2.2. I was checking the ODPRequest class on infocenter they document this class in SUP 2.2. So, Is it only available with SUP 2.2 or it is also there in SUP 2.1 #ESD3. My project is currently on SUP 2.1 #ESD3.

Regards,

saurabh

0 Kudos

Hi All,

Well, I have gone a small step forward...

The issue is that Memory is not getting allocated to the SUPBigBinary object and for because of that the problem is coming....

Can someone help me out on that??

Regards,

Saurabh.

_IvanFemia_
Active Contributor
0 Kudos

Hi,

try

SUPBigBinary *img = [[SUPBigBinary alloc] init];

regards

Ivan

0 Kudos

Hi Ivan,

     Thanks for the help. I have tried the same. but it throws an exception when I use openForWrite method. Exception is: Unrecognised selector sent to the class.

Regards,

Saurabh.