cloud-sdk-js
cloud-sdk-js copied to clipboard
@sap/cloud-sdk-vdm-attachment-service how to read attachment media streams
Dear Cloud SDK Team, I would like to get the media streams of documents attached to my S4 business objects. An example of the equivalent OData request is: http://mys4system/sap/opu/odata/sap/API_CV_ATTACHMENT_SRV/AttachmentContentSet(DocumentInfoRecordDocType='YBO',DocumentInfoRecordDocNumber='10000000031',DocumentInfoRecordDocVersion='01',DocumentInfoRecordDocPart='000',LogicalDocument='00155D3C540E1EEB8BE638CD39A862CE',ArchiveDocumentID='00155D3C540E1EEB8BE638CD39A8A2CE',LinkedSAPObjectKey='M1-ACA01',BusinessObjectTypeName='MARA')/$value I think the corresponding OData VDM package is @sap/cloud-sdk-vdm-attachment-service, but I was unable to get the media streams. I read an old post in stack overflow where your colleage Dennis Hempfing, said that this wasn't posible with the Javascript VDM. Is there any way to achieve it? Thanks in advance. Best regards, Marc
Hi @socenmarc,
Thanks for a good question. I think this recent SDK update to configure Axios to get a response as `arraybuffer might help.
@jjtang1985, check me, please.
Hi @socenmarc ,
Dennis said it was not possible with the Javascript VDM, because of some missing functionalities:
- The SAP Cloud SDK can generate URL
/AttachmentContestSet(...)
by usinggetByKey
function of the request builder and here is the doc. However, currently the SDK cannot handle the/$value
part, which will be a feature request. - When downloading an attachment, additional
axios
option is needed, which was supported recently and @artemkovalyov shared the right doc.
May I ask you the urgency of this request? Are you working on some live systems or maybe it's just a PoC project?
Thank you. Best regards, Junjie
Hi @artemkovalyov and @jjtang1985, Thank you very much for your answers. Junjie, we are developing a side-by-side extension for S4, and our development phase will finish in two months. For now, we will implement it by calling the OData request, but it would be great to use Cloud SDK as we do in all other integrations. Thanks for your support. Best regards, Marc
Hi @socenmarc , thank you for your reply. I added this feature request to our backlog with medium priority as you have a workaround.
@artemkovalyov FYI.
Best, Junjie
Hello, @jjtang1985
Just run into the same issue. We could add the $value
at the end of the path with .appendPath('/$value')
but the hardcoded query parameter $format=json
is apparently what makes the OData request fail.
Is there an estimated date for this feature? We are just starting an S/4HANA project and it would be good to have this feature.
Best regards.
Hi @ctapisab ,
for the time being, maybe you can try the generic http client, as mentioned in another issue you created here.
By the way, could you please share your timeline for this request? Also, are you working on a live system or maybe a PoC project?
@artemkovalyov FYI
Best regards, Junjie
Thanks for the repsonse @jjtang1985 ,
We are working in a new S/4HANA Implementation and the development of this functionality should end in ~July 28th.
We will try using the generic http client to read attachment.
Just one more question (if it's necessary I will open another issue for this): when trying to create an attachment (POST request) the x-csrf-token is needed. I understood according to documentation that the option { fetchCsrfToken: true }
could be used to tell SAP Cloud SDK to retrieve this token automatically, but it seems the HEAD request it does fails with an 401
status. I debugged and apparently the authorization
header was being sent correctly (with user/pw from destination config.), so my question is if this fetchCsrfToken
option has any limitation or restriction or it should work?
Best regards, Christian Tapia
Hi @ctapisab ,
thanks for sharing the time line (FYI @artemkovalyov ).
For the csrf token, in general, it should work and here is a known bug.
I would suggest to make a simple GET request to make sure the credential is working, and then test another non-GET request with json body instead of binary.
Feel free to create a new issue with more details if the csrf token does not work, as it's not related to this issue.
Best regards, Junjie
Hi, @jjtang1985 ,
Yes, I got it working by fetching the csrf token with a GET and then passing it to the POST request (I also had to pass the cookies). So the problem may be related to the bug you mentioned.
Thanks for your response. Best regards.
Hi @jjtang1985, @socenmarc,
Would the existing solution based on the generic client work for you to go live? Or you'll need production-ready support for this service from the SDK? I want to plan our timeline regarding fixing this. Because many parties are involved it might take some time.
Hi @artemkovalyov, it is fine for us the current solution based on the generic client. Thank you for keeping us informed. Best regards, Marc
Thanks for the quick clarification @socenmarc. We'll keep this open and keep you posted when the type-safe API supports this.
Hi, what is the status on this @artemkovalyov ? Thanks!
Hi @tarran-durham , the priority is not high as some workaround are mentioned above.
Would you like to share go live timeline, if possible or are your working on a PoC? @marikaner , FYI.
Hey @tarran-durham, @ctapisab, we recently removed the $format
query parameter that was causing issues with the proposed solutation above. This is currently available as a canary version only, we will most likely release a new version in roughly 2 weeks.
I'll close this ticket, as the generic http client is the recommended way to handle this.