cancel
Showing results for 
Search instead for 
Did you mean: 

How to send additional parameters with file upload

Former Member
0 Kudos

Hi,

When I upload a file, using SAP GW, de "data" parameter is fileld with the file. However, I'd like to send additional info with the post method.

In the backend the "create_stream" method is called, and I noticed there is an import parameter "IT_KEY_TAB", so it must be possible to send some additonal parameters with the request.

In short: is there anyone who can tell me how I can add a parameter e.g. "Guid" in this post method:

jQuery

     .ajax({

     type : 'POST',

     url : "xxx/sap/opu/odata/sap/ZK_MOBILE_SERVICEDESK_SRV/Files",

     headers : oHeaders,

     cache : false,

     contentType : false,

     dataType : "json",

     processData : false,

     data : file,

          success : function({}),

     ...


Thanks,


RW

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

Hi Robbe,

I think you have two options:

1. you can use http request header parameter slug, just insert this into oHeaders and then you will see its value in iv_slug in create_stream. You can make your own logic to separate more fields if you need.

2. you can add you own request header parameter. And then read it according to solution in this thread

Best regards,

Peter

Former Member
0 Kudos

Hi Peter,

Thanks for your answer! I'll use option 1.

Kind regards,

RW

Former Member
0 Kudos

Hello Peter,

I have used http request header parameter slug, but I cannot see any value in iv_slug in create_stream method. Can you guide me on this?

Answers (3)

Answers (3)

MattHarding
Active Contributor

Hi Robbe,

If you are posting a file to a navigation property that points at the corresponding media link entityset; then the key fields are filled with the previous entity.

e.g. Posting a file to Employees('12345')/Attachments will automatically give you the employee id as a key within create_stream.

Cheers,

Matt

0 Kudos

Thanks! Posting via navigation property works good.

tom_parsons
Participant
0 Kudos

For some help implementing Matt's suggestion, take a look at . It allows you to send a number of keys in your URL.

So things like this are possible using POST:

Attachments(Key='1234567890',EmployeeNumber='5678',FileName='test.gif')/File

former_member184867
Active Contributor
0 Kudos

IT_KEY_TAB is for different purpose.

To pass extra parameter you may use a header called SLUG. This will be received in IV_SLUG parameter in the DPC method. If you have multiple things to pass you can pass everything in SLUG separated by some separator 

Former Member
0 Kudos

Atunu,

Just out of curiosity: for what purpose is the it_key_tab in the create_stream method?

Kind regards,

RW

former_member184867
Active Contributor
0 Kudos

IT_KEY_TAB holds the key information. If the URL is like /servicename/EntitySetName(Key1=1, Key2=2), you  gey Key1 = 1 and Key2 = 2 in the IT_KEY_TAB ..

Former Member
0 Kudos

Hi Atanu,

so if you need to send a parameter which is a key for that Entity, we can send it as you stated? Would that work along with create_stream?

Thanks,

Peter

former_member184867
Active Contributor
0 Kudos

Not sure.. I did not try .. at this moment I do not have a service with media type to quickly check this