199
Views
10
Comments
Solved
PDF / Binary Downloading corruption issue
Question

Hi. In my reactive web app (and mobile) I want to download a PDF that was saved to the server. It appears though that the binary data is getting corrupted somehow. Can anyone help please? 

To simplify the problem, I uploaded a PDF as a resource to my OutSystems project and then load the binary data


I then call some JavaScript to display (and download for test) my binary PDF as a blob, but Adobe says the document is corrupted.


I'm fairly confident the JavaScript is ok. But I note that the document size once downloaded is different to the original PDF (larger than the original) so I believe it's being corrupted at the Binary level somewhere before the JavaScript. Can any one help?

Please note that I want to avoid using server side extensions for security policy reasons that are beyond this article so it needs to be a client side solution to manipulate the binary (if it needs manipulating).


Thanks in advance

UserImage.jpg
Richard Falkner
Solution

Benjith Sam wrote:

Hi Richard,

After researching a lot about the implementation, finally I got success :)

See this DownloadFile Demo App

Please find the attached .oml solution file


Observation

If we pass/set the link.href value as the Resource file Runtime Path value then also the file gets downloaded successfully.

Hope this helps you!


Regards,

Benjith Sam

 ... Ahhh. Thanks Benjith. I see there is a Base64 conversion in your example. Maybe that is the encode that's missing from mine. I'll give this a go and feed back. Thanks

 

2022-02-28 05-37-25
Ronny

I think you can use a link that destination to a screen action. In the screen action, you can use the download widget. The file content can link to the resources 

Resources.RulesRegulations_pdf.Content

Hope that helps

UserImage.jpg
Richard Falkner

ronny wrote:

I think you can use a link that destination to a screen action. In the screen action, you can use the download widget. The file content can link to the resources 

Resources.RulesRegulations_pdf.Content

Hope that helps

 

 Hi Ronny. Thanks for your reply. Unfortunately I can't use the download solution. The example you suggested works but in my scenario, I will need to be able to get to binary directly and launch into the browser via JavaScript without saving to the phone storage. Whatever the Download does looks to correct the corruption so if you know why that is it would be really helpful? Is there some encoding/decoding going on during the download? Note that I'm using O/S 11.0.614 reactive so my download doesn't have the Mime-Type or Save to Disk option.

2017-12-13 08-27-28
Joey Moree

Hey Richard,

So you are saying that the binary you retrieve from the database, when using the download function works correctly?

I think using application/pdf (like you do in the javascript) will tell the browser to try and open it (or atleast chrome does), try changing it to application/octet-stream to see if it correctly downloads then?
It might also be due to the size of the file? Some corruption might happen in the data in javascript when sending it over the line.

Take a look at this: https://stackoverflow.com/questions/20287600/ajax-response-gives-a-corrupted-compressed-tgz-file/20545165#20545165 this might help you out.

UserImage.jpg
Richard Falkner

Joey Moree wrote:

Hey Richard,

So you are saying that the binary you retrieve from the database, when using the download function works correctly?

I think using application/pdf (like you do in the javascript) will tell the browser to try and open it (or atleast chrome does), try changing it to application/octet-stream to see if it correctly downloads then?
It might also be due to the size of the file? Some corruption might happen in the data in javascript when sending it over the line.

Take a look at this: https://stackoverflow.com/questions/20287600/ajax-response-gives-a-corrupted-compressed-tgz-file/20545165#20545165 this might help you out.

 Hi Joey, I've noticed that the issue seems to occur much earlier than I thought. My actual PDF (in the resources just for testing) is 181.3KB in size, but when I read its contents (binary) property and pass it into JavaScript as Binary it is 242K in size so something must be corrupting it as I pass the Binary type into the JavaScript. 

I'd expect my "binary" (Binary) value to be 181.3K in size, but when I pass it as a parameter $parameters.Blob into my JavaScript, it's showing up as 242KB in size

Something is encoding or corrupting the Binary data even as it's passed into the function making it bigger.

 

2021-03-18 21-03-15
Benjith Sam
 
MVP

Hi Richard,

After researching a lot about the implementation, finally I got success :)

See this DownloadFile Demo App

Please find the attached .oml solution file


Observation

If we pass/set the link.href value as the Resource file Runtime Path value then also the file gets downloaded successfully.

Hope this helps you!


Regards,

Benjith Sam

ReactiveDownloadFile.oml
UserImage.jpg
Richard Falkner
Solution

Benjith Sam wrote:

Hi Richard,

After researching a lot about the implementation, finally I got success :)

See this DownloadFile Demo App

Please find the attached .oml solution file


Observation

If we pass/set the link.href value as the Resource file Runtime Path value then also the file gets downloaded successfully.

Hope this helps you!


Regards,

Benjith Sam

 ... Ahhh. Thanks Benjith. I see there is a Base64 conversion in your example. Maybe that is the encode that's missing from mine. I'll give this a go and feed back. Thanks

 

UserImage.jpg
Richard Falkner

Richard Falkner wrote:

Benjith Sam wrote:

Hi Richard,

After researching a lot about the implementation, finally I got success :)

See this DownloadFile Demo App

Please find the attached .oml solution file


Observation

If we pass/set the link.href value as the Resource file Runtime Path value then also the file gets downloaded successfully.

Hope this helps you!


Regards,

Benjith Sam

 ... Ahhh. Thanks Benjith. I see there is a Base64 conversion in your example. Maybe that is the encode that's missing from mine. I'll give this a go and feed back. Thanks

 

 That's solved it. The binary data needed to have a base64 conversion before I could use it. Thanks Benjith.

 

2021-03-18 21-03-15
Benjith Sam
 
MVP

Richard Falkner wrote:

That's solved it. The binary data needed to have a base64 conversion before I could use it. Thanks Benjith. 

You're most welcome, Richard :)

Glad I could be of help :)

I guess that you marked your own reply as a solution by mistake instead if you mark my answer as solution it will help other forum members searching for the same and personally it will be a motivation factor for me :)


Kind Regards,

Benjith Sam

UserImage.jpg
Richard Falkner

Thanks for your help everyone. This is now solved.

UserImage.jpg
Richard Falkner

Thanks Benjith. I've correctly marked it now. Thanks again for your help

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