Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

I am hosting a HTML file in Sybase 10 and it works so far good.

I want now to add img Tag in my HTML but it doesnt work, because img Tag expects a relative path to the img as "src".

Now the question is, what is the current folder for my webservice? I tried the path of dbsrv10.exe but without success "C:\Program Files (x86)\SQL Anywhere 10\win32"

The script in DB looks something like:

create PROCEDURE hello_world( )

RESULT (html_doc long varchar)

BEGIN

CALL dbo.sa_set_http_header( 'Content-Type', 'text/html' );

select '<!DOCTYPE html>\n'

|| '<html lang="en">\n'

|| '<body>\n'

|| 'hello world
\n'

|| '<imgg srcc="010.jpg">\n'

|| '</body>\n'

|| '</html>\n';

END;

create SERVICE hello_world TYPE 'RAW'

AUTHORIZATION OFF

USER DBA

AS CALL hello_world;

asked 27 Jun '19, 03:26

Baron's gravatar image

Baron
2.1k136149177
accept rate: 48%

edited 27 Jun '19, 03:38

One possible solution was for example to share the folder containing the image and then use "file://computername/folder/010.jpg".

So something like: "<<imgg srcc="file://computername/temp/010.jpg">>"

(27 Jun '19, 03:44) Baron

you should create a service that will return the images from DB using the provided URL. On high-level, just create an HTTP procedure that listens: /prefix/***

http://sqlanywhere.blogspot.com/2015/01/calling-stored-procedures-from-html.html

and when you see a request that has: /prefix/image.jpg, you can read the JPG file from your table and return as a binary data.

URLs starting from file:// -- are local URLs. The browser will try to find the image from the user's computer.

(27 Jun '19, 03:54) Vlad
Replies hidden

Do you mean that I should read the images from its path and save it in DB? And then the Webservice takes the image from DB and returns it as a response? This causes me a big problem with DB-Size!!

Anyway, could you please tell me how can I read a jpg file and save it in DB-Table as binary?

(27 Jun '19, 07:53) Baron

Well, the web service could also return an image file from a directory which is accessable from the database server. You can use xp_read_file() to read the file contents as blob - if you store it within a SQL variable (or a table column), be sure to use a varbinary type.

Whether you choose to store images in the database or in a file directory is up to you.


FWIW, the SQL Anywhere samples include several web service samples, among others - I guess also for v10:

image_readfile.sql


A small demonstration of how to use xp_read_file to retrieve images from a local disk and return it as the response to an HTTP request.

(27 Jun '19, 08:35) Volker Barth

Thanks for the answer, is great to have a way to read the jpg files from disk and include it then in my HTTP response. In this way I can avoid using IIS which is very system independent.

Only I couldnt open the links/attachments in your last comment (I see only plain text with gray background)

(27 Jun '19, 09:07) Baron

It is no link, just a snippet from the reame.txt file of the SQL Anywhere 12\Samples\SQLAnywhere\HTTP\ samples directory. I think your install should include the same files (probably in a different version).

(27 Jun '19, 10:35) Volker Barth
showing 2 of 6 show all flat view

Hi Sarkis,

maybe this sample helps: https://www.db-tecknowledgy.info/fileshare/public/SQLAnyIcon.SQL
I provide the Image binary as a service. In case you want images from multiple or large server side files, you can utilize xp_read_file rather than specifying the binary content literally.
The logic around provides a framework and sample for a root service listing the available "open" services in the DB, with the SQL Anywhere product icon as favicon. I just verified that it runs against v.17, but I'm quite sure that I used it with older versions in the past.

HTH
Volker

permanent link

answered 27 Jun '19, 08:48

Volker%20DB-TecKy's gravatar image

Volker DB-TecKy
5453715
accept rate: 25%

edited 27 Jun '19, 08:55

Thank you all. I found a good solution using IIS, so I added a virtual directory in IIS and then used the full URL in my HTML to access each photo from this virtual directory.

Something like: <imgg srcc="http://my_ip/my_directory/111.jpg">

I write imgg instead of img and srcc instead of src in order to avoid HTML interpreting on this page.

(27 Jun '19, 09:00) Baron
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×65

question asked: 27 Jun '19, 03:26

question was seen: 994 times

last updated: 27 Jun '19, 10:35