This is a migrated thread and some comments may be shown as answers.

Retrieve image from SQL filestream

3 Answers 137 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Cecil
Top achievements
Rank 1
Cecil asked on 08 Dec 2015, 08:41 PM

My Application has photos that are stored in a SQL using a filestream column.

The question I have is, is there a method, plugin, or whatever for retrieving those photos?

 

3 Answers, 1 is accepted

Sort by
0
Anton Dobrev
Telerik team
answered on 09 Dec 2015, 03:33 PM
Hi Cecil,

Thanks for your question.

You can map this column to a field in your Backend Services content type (it will be mapped to a field of type Object). Then you can use the image data in your client app from this field. The values of the column will be received in the client app as a base64 string.

You can use the string as value of the src attribute of the IMG tag:
<img alt="MyImage" src="data:image/png;base64,MY_BASE64_STRING_HERE" />

I hope that this answers your question.


Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Cecil
Top achievements
Rank 1
answered on 17 Dec 2015, 06:56 PM

Thanks Anton. 

That worked so well that I would like to expand on this.

From that same filestream database, how would I retrieve and display a pdf?

0
Anton Dobrev
Telerik team
answered on 18 Dec 2015, 05:22 PM
Hello Cecil,

You can retrieve the base64 string representation of a PDF file in the same way. 

For iOS apps, you can construct a data URL like data:application/pdf;base64, base64StringHere to open the PDF in the device browser.

For example:
<a id="pdf-link">Get PDF</a> /* holder of the link to the PDF
 
/* when you have the base64 string use it as a value of the href attribute to construct the link*/
var src = "data:application/pdf;base64," +str;
             
var img = document.getElementById('pdf');
img.href = src;

For Android devices, a more robust solution would be:

- Get the base64 string
- Convert the base64 string to a byte/binary array
- Save it to the device file storage as a file
- Open the PDF from the device file storage

You can refer to this example app for reading a local PDF file. You can also use the File Transfer plugin to write the base64 string to the local storage.

I hope that this helps. Let me know if you have questions.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
General Discussion
Asked by
Cecil
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
Cecil
Top achievements
Rank 1
Share this question
or