Skip to Content

SAP Cloud Platform Android app can't upload media

Just a quick followup: I am 100% sure the file I try to upload is existing and I can access it. I proved this by creating a copy of it just before processing.

------------------------

Hi,

I'm developing an Android app and I'm using the CV_ATTACHMENT_SRV OData service. The problem is that I cannot upload media to this service.

I created a ByteStream by using the method,

ByteStream content = ByteStream.fromInput(inputStream);

I tried to use the

createMedia(EntityValue entity, StreamBase content, HttpHeaders headers)

method of the service to upload an image where the entity is basically an instance of 'OriginalContent', the content is the ByteStream created earlier, and the headers contain some additional information related OriginalContent.

This is what I get:

com.sap.cloud.mobile.odata.DataStreamException: stream is closed  

at com.sap.cloud.mobile.odata.http.OKByteStreamBody.writeTo(OKByteStreamBody.java:46)  

at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:59)  

at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)  

...

I tried to figure out if I have access to the file I want to upload so I tried the above mentioned method with having a file on the external storage and packaged in the project. None of them worked.

Did you guys meet this kind of situation? I'm having a hard time finding similar situations. Please help.

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on May 19 at 08:40 PM

    Hi Tamas Makranczi,

    This error will happen when the StreamBase value you've sent to createMedia method is null. Have you debugged to check if the ByteStream class is being able to really open the file in question?

    Since you didn't share how you are setting the inputStream variable, here are some options:

    android.content.Context context;
    //External resource (file:// or http://)
    InputStream inputStreamExt = context.getContentResolver().openInputStream(uri);
    //Local resource that belongs to your application's res folder
    InputStream inputStreamInt = getResources().openRawResource(R.raw.blank);
    

    Best regards,
    Ivan

    Add a comment
    10|10000 characters needed characters exceeded

    • Hey Ivan, thanks for the reply. You are right I didn't share how I open the input stream. I tried the local resource version and it doesn't seem to work. I also tried to create the ByteStream with the fromFile method, and I haven't tried the first version you mentioned. In any case, the ByteStream instance was not null. Is there any way to know if the ByteStream instance is opened correctly?

      Thanks!

  • Posted on May 20 at 02:03 PM

    Hey Ivan, I found the solution. Turns out I used these libraries at the time of the exception:

    implementation group: 'com.sap.cloud.android', name: 'fiori', version: 3.0.0
    implementation group: 'com.sap.cloud.android', name: 'onboarding', version: 3.0.0
    implementation group: 'com.sap.cloud.android', name: 'odata', version: 3.0.0
    implementation   group: 'com.sap.cloud.android', name: 'foundation', version: 3.0.0

    and got rid the ugly exception by upgrading the version of one of these libraries to 3.0.5 (odata I guess?). I upgraded them all anyway.

    Do you have a quick link towards the changelogs maybe? That would help a lot.

    Anyway thanks for your help!

    Best regards,

    Tamas Makranczi

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Tamas Makranczi

      That information isn't publicly available. All I could find were the release notes (when you download the SDK from Service Marketplace, you have a small button that enables you to open the SAP release notes).But the information on SAP Notes aren't what you are looking for. They contain new features information only.Regardless, for SCP you should always use the most up-to-date version as the solution is constantly being updated by SAP.Best regards,
      Ivan

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.