81
Views
9
Comments
Solved
Can't read the downloaded file(PDF/PNG/XLSX,...)
Question
Service Studio Version
11.54.33 (Build 62940)

Hello,

Good day,

Steps(OS reactive):

1. I have uploaded a PNG image to the server.

2. And I'm trying to get that image via API(not exposed from OutSystems).

3. Passing Document id and getting "text" response with "Application/Octet-stream" content type.

4. The API response is like this, 

5. I've tried to convert this text to binary and tried to download it.

6. I can able to download it with the same size(just 2kb) which I've uploaded.

7. But when i trying to open that, I couldn't and showing the below popup, 

8. Note: This issue is not only for PNG, This is for all like PDF,XLSX,PPT,...

9. And even i've tried in JS way as well, 

But, even i'm getting the same issue, i couldn't open those files.

Note : This is the 3rd party API, and It is working as expected in .Net, i'm facing this issue only on OS.

Anyone has any idea about it?

Thanks in advance.

2024-11-07 03-28-42
Stuart Harris
Champion
Solution
Hello thanigaiarasu,
The server is returning you a binary file. The content type application/octet-stream means it is a binary, and the image looks like a binary PNG file should look if opened in a text editor.

If you could explain more about how you are integrating with the API that could help.
Essentially, when you said that it is returning a "text response", I would like to understand what you mean; i.e. do you mean to say the response in your API definition is a text data type? If so, try changing it to BinaryData.

If there is an attribute for the content of the response, it should be BinaryData in OutSystems. Then you should be able to store or download that content as a file.

I hope this helps.


Kind regards,

Stuart

UserImage.jpg
Thanigaiarasu Arumugam

Hello Stuart,

As you told, API's return data type is "Text" and that's why i've converted that from text to Binary. But now i've tried this too while assigning, 

But this time also i'm getting same, i can able to download the file but can't read/view the file.

What should i do now.

Tried:

1. Did "TextToBinary"

2. Did "TextToBinarydata" while variable assignment.

3. Passed text upto the client action and played with JS Blob as well, but that time file size increased and even i cant view/read it.

Any idea.

Thanks in advance.

2024-05-08 06-29-37
Prince Aadil Khan Panwar

Hi @thanigaiarasu arumugam,

try to get the external address for the image from the 3rd party API, as we use into the image widget for external link 

Hope this helps

Thanks 

Prince

UserImage.jpg
Thanigaiarasu Arumugam

Hello Prince,

External url(Physical path) is not good here, because folder name can be change often. That's why we are trying to hit an API.

Thanks.


2021-11-19 11-12-44
Rui Mendes

Hello thanigaiarasu, 


 I was looking at your explanation of the problem and a possible cause of not being able to access the binary of the images may have to do with the server sending the compressed package. It is a very common practice in APIs.


I suggest you visit the GZIP test page https://ruihmendes.outsystemscloud.com/Gzip/ this component allows you to decompress the package to access its content.


After confirming that it works in your case, you can install it on your server and mark it here on the forum as a solution for other members with similar problems to also find the solution. 


Regards,

UserImage.jpg
Thanigaiarasu Arumugam

Hello Rui Mendes,

It's just 2KB file, even i can't able to view it. The problem is i can download the file with the same size, but can't view it.

Thank you


2024-11-07 03-28-42
Stuart Harris
Champion
Solution
Hello thanigaiarasu,
The server is returning you a binary file. The content type application/octet-stream means it is a binary, and the image looks like a binary PNG file should look if opened in a text editor.

If you could explain more about how you are integrating with the API that could help.
Essentially, when you said that it is returning a "text response", I would like to understand what you mean; i.e. do you mean to say the response in your API definition is a text data type? If so, try changing it to BinaryData.

If there is an attribute for the content of the response, it should be BinaryData in OutSystems. Then you should be able to store or download that content as a file.

I hope this helps.


Kind regards,

Stuart

UserImage.jpg
Thanigaiarasu Arumugam

Hello Stuart,

As you told, API's return data type is "Text" and that's why i've converted that from text to Binary. But now i've tried this too while assigning, 

But this time also i'm getting same, i can able to download the file but can't read/view the file.

What should i do now.

Tried:

1. Did "TextToBinary"

2. Did "TextToBinarydata" while variable assignment.

3. Passed text upto the client action and played with JS Blob as well, but that time file size increased and even i cant view/read it.

Any idea.

Thanks in advance.

UserImage.jpg
Alexandre Yip

Hi thanigaiarasu arumugam

Can that text be provided in base64 format? 

try this action 

https://success.outsystems.com/documentation/11/reference/outsystems_apis/binarydata_api/

Base64ToBinary

Converts Base64 Text into BinaryData.

Inputs

Base64Type: Text. Mandatory.

Base64 Text to convert to BinaryData.

Outputs

BinaryType: BinaryData.

Result of conversion from Base64 Text to BinaryData.

Hope that it helps you 

UserImage.jpg
Thanigaiarasu Arumugam

Hello Alexandre Yip,

I've tried this "Base64 to Binary" as well. But this time i got an error like "this is not the base64 content". so it seams like the API response is not the base64 but the response's data type is text only. That's why i did text to binary. But unfortunately i can download the file with same size but cant read/view it.

Thanks


2024-11-07 03-28-42
Stuart Harris
Champion

Hello thanigaiarasu,

I understand the response is set as Text, however according to the content type it is not text, it is binary. So there is no need to convert it from text to binary. The problem is the text type on the response is incorrect.

Could you clarify how the text type was set on the response? Have you tried changing the text type in the response to Binary Data? If so, what happened, was there an error message?

Kind regards,

Stuart


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.