cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Image to SAP via iOS Native app (SUP 2.1.3)

Former Member
0 Kudos

Hi All,

We are facing problem to upload the image to SAP via SUP 2.1.3 from iOS native app.

With the following piece of code, we are able to send the file to SAP, but file is not visible in proper format. The size of image on SAP appears as 1KB only.

I created a Dummy MBO and put operation which does the upload image operation.

Below is the code which upload the image on SAP:

  @try{

       

        UIImage *camerafile = [UIImage imageNamed:@"helloi.jpg"];

        NSData *cameraData = UIImageJPEGRepresentation(camerafile, 1);

       long long size = [cameraData length];

     

        [FIFIDB synchronize];     //shell MBO

       

        FIAddPictureList *returnDummies = [FIAddPicture findAll];

     

  //      FIAddPicture *fap;

       

   

        if ([returnDummies length] > 0)

        {

            for (FIAddPicture *oneRec in returnDummies)

            {

               

                FIAddPicture *fap = oneRec;

               

                SUPBigBinary *fileContent=fap.FILE_CONTENT;

          

               

                [fileContent openForWrite: 0]; //13286

                [fileContent write:cameraData];

                [fileContent flush];

                [fileContent close];

               

               

                [fap create:@"helloi" withIV_OBJECT_ID:@"0005000002" withIV_FILE_EXT:@"jpg"];

               

                [fap  save];

                [fap  submitPending];

                [FIFIDB synchronize];

                break;

            }

        }

       

    }

    @catch (NSException *exception) {

        NSLog(@"FAILED: updating record");

        NSLog(@"%@: %@", [exception name],[exception reason]);

        return;

    }    ///////////////////////////////////////////////////////////////////////

   

}

Please help to resolve the issue.

Accepted Solutions (1)

Accepted Solutions (1)

midhun_vp
Active Contributor
0 Kudos
  • What is the data type of that particular field in BAPI/RFC.It should be Xstring.
  • And the respective data type for that field in MBO will be bigBinary and the image sending from device should be in Binary.
  • Check in the SUP server log whether the image in binary format is reaching to SUP or not. There by you can find where the issue comes.

- Midhun VP

Former Member
0 Kudos

Thanks Midhun,

Bapi has input parameter as data type XSTRING.

and we are using SUPBigBinary datatype in MBO.

Please can you suggest more on this.

Regards

Saket

brenton_ocallaghan
Active Participant
0 Kudos

Hi Saket,

Try re-ordering your statements. I have found, when dealing with BigBinary in SUP 2.1 ESD#3 that you need to do your create before setting your binary data:

FIAddPicture *fap = oneRec;

              

[fap create:@"helloi" withIV_OBJECT_ID:@"0005000002"withIV_FILE_EXT:@"jpg"];

SUPBigBinary *fileContent = fap.FILE_CONTENT;

[fileContent openForWrite: 0]; //13286

[fileContent write:cameraData];

//[fileContent flush]; // not sure you need this?

[fileContent close];

[fap  save];

[fap submitPending];

That should work for you - you need to have created the new object before adding the binary data - otherwise it won't work. Not sure you need the second save but you can try it out yourself.

Let me know if this still doenst work - i've tried it a few times with no issues.

Cheers,

Brenton.

Former Member
0 Kudos

Thanks a lot

Brenton.....
Former Member
0 Kudos

Guys, One Quick help needed,

We are trying to send image of 3-5 MB from device and we use the following code to represent the image:

  NSData *cameraData = UIImageJPEGRepresentation(camerafile, 1);

we tried with (camerafile, 0.8), 0.5 and 0.3,

Its kind of hanging at [FIFIDB synchronize];

small sized images are working fine but big size like 3 - 5MB they are giving trouble.

Is there anything we need to increase the timeout for synchronization and if yes how can we do that?

Help will be really appreciated.

Saket


brenton_ocallaghan
Active Participant
0 Kudos

Hi Saket,

This would be a different issue but as far as I am aware, the call to "synchronize" is a blocking call so therefore you would literally wait at that command until all 3 to 5 MB have synchronised.

Usually when dealing with this kind of data you want to let the DB go off and synchronise all on its own so just call save on the entity and then submitPending on the same entity.

If you need to call synchronise at all use the non-blocking method as seen in the example here.

If the data is still not getting to where it needs to be, then I would look at your infrastructure that you are using between your mobile device and the server. If it is unable to handle the streaming that is happening to transfer this data then you might see problems (hence why smaller images/data works). Once your image or data goes over a certain size then some proxy in the middle might kill the connection?

Hope that helps,

Brenton.

Former Member
0 Kudos

Thanks for quick response Brenton, i increased the server timeout and it works.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi All,


  Im developing native iOS application using sup 2.1.3 . Im getting error While retrieving  image from SUP database. Here i'm trying to get image from database and show in imageView.can any one help me how to fix this issue?


In database image datatype is  'LONG Binary' .


My table Schema:


CREATE TABLE dba.ImagesTable (

RowID INT NOT NULL,

ImageName VARCHAR(20) NOT NULL,

PhotoData LONG BINARY NOT NULL,

)

IN SYSTEM

;

ALTER TABLE dba.ImagesTable

  ADD CONSTRAINT ASA137 PRIMARY KEY CLUSTERED (RowID)

;

ALTER TABLE dba.ImagesTable

  ADD CONSTRAINT ASA138 UNIQUE NONCLUSTERED (RowID)

;



in Xcode:


            [SUP107SUP107DB synchronize];

        

            SUP107ImagesTable *imgTable =[[SUP107ImagesTable alloc]init];

        

            SUP107ImagesTableList *list =[SUP107ImagesTable findAll];

            SUP107ImagesTable * oneRecord =[list objectAtIndex:0];

        

            NSLog(@"rowId:%d---imageName:%@---photoData:%@---photoLenght:%d",oneRecord.rowID,oneRecord.imageName,oneRecord.photoData,oneRecord.photoDataLength);

        

            NSData *tempData =[[NSData alloc]init];

            SUPBigBinary *responseBinaryData = (SUPBigBinary *)oneRecord.photoData.value;

        

            @try {

                [responseBinaryData openForWrite:[oneRecord.photoData length]];

                [responseBinaryData write:tempData];

            }

            @catch (NSException *exception) {

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

            

            }

        

        

        

            UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(50,50,100,100)];

            [self.window addSubview:imgView];

            UIImage * tempImage =[UIImage imageWithData:tempData];

            imgView.image = tempImage;

        

            [responseBinaryData close];

Error Log:

Printing description of list:

[ ImagesTable =

      rowID = 1,

      imageName = Apple,

      photoData = SUPBigBinary: column=c pending=1 allow_pending_state=1 table=sup107_1_0_imagestable mbo=0x0 key=(null) ,

      pending = 0,

      pendingChange = N,

      replayPending = 0,

      replayFailure = 0,

      surrogateKey = 300001,

      replayCounter = 0,

      disableSubmit = 0,

      photoDataLength = 90656,

      isNew = 0,

        isDirty = 0,

        isDeleted = 0,

]

2014-04-02 18:42:15.150 SUP102[2873:70b] rowId:1---imageName:Apple---photoData:SUPBigBinary: column=c pending=1 allow_pending_state=1 table=sup107_1_0_imagestable mbo=0x0 key=(null) ---photoLenght:90656

Printing description of responseBinaryData:

<OS_dispatch_data: data[0xc891b40] = { leaf, size = 90656, buf = 0x1213a000 }>

2014-04-02 18:42:33.304 SUP102[2873:70b] -[OS_dispatch_data openForWrite:]: unrecognized selector sent to instance 0xc891b40

2014-04-02 18:42:33.305 SUP102[2873:70b] exception: -[OS_dispatch_data openForWrite:]: unrecognized selector sent to instance 0xc891b40

2014-04-02 18:42:33.305 SUP102[2873:70b] -[OS_dispatch_data close]: unrecognized selector sent to instance 0xc891b40

2014-04-02 18:42:33.306 SUP102[2873:70b] [ERROR] [AppDelegate.m:497] NSInvalidArgumentException: -[OS_dispatch_data close]: unrecognized selector sent to instance 0xc891b40




can any give some help how to fetch PhotoData and show that one in UIImageview in ios?