How To use an external image

Questions, tips and tricks and techniques for scripting in Servoy

How To use an external image

Postby Marco R. » Tue Jan 04, 2011 1:17 pm

Hi all,


I have to use more images (that,sometimes,will be saved in another server for a backup),
so I wouldn't save them into the db to avoid having to sincronize and manage them twice.
By this need,I've tried to use the html to point directly on the image(<html><body><img src = 'C:\\myImage.jpg'></body></html>) but without results.

My question is:
Using the html,does exist a way to point to an external image?

if not:
Does exist another way to do this?


Thanks in advance,

Marco
Marco Rossi
Freelance

Main development environment: Servoy 6.1.6 - 7.4.3, Java 1.6u45,7u71 Windows 7/CentOS
Marco R.
 
Posts: 203
Joined: Thu Mar 19, 2009 12:37 pm

Re: How To use an external image

Postby Joas » Tue Jan 04, 2011 1:38 pm

Marco R. wrote:I've tried to use the html to point directly on the image(<html><body><img src = 'C:\\myImage.jpg'></body></html>)

Try this:
Code: Select all
<html><body><img src = 'file:///C:/myImage.jpg'></body></html>
Joas de Haan
Yield Software Development
Need help on your project? yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 842
Joined: Mon Mar 20, 2006 4:07 pm
Location: Leusden, NL

Re: How To use an external image

Postby jcompagner » Tue Jan 04, 2011 2:30 pm

are we talking here about a smart client? and then the c:\ where you talk about is the c: drive of the smart client? (so not a server or developer drive?)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: How To use an external image

Postby Marco R. » Tue Jan 04, 2011 5:41 pm

@Joas:

It works,Thanks Joas!


@jcompagner:
Yes is the c: drive of smart client(for now I need only to choose the way that I have to take)

For who is reading this topic:
I have token another way because I have to work both with local and with remote files..I have token the related JSFile of myImage.jpg(using convertToRemoteJSFile) and I have convert it into a JSImage object by the code:

Code: Select all
var _file = plugins.file.convertToRemoteJSFile('/site_off.jpg')       
plugins.images.getImage(_file.getBytes())


After this I have resized the JSImage to create a miniature.

I have a new question: what is the best way to send the new miniature-image to the remote folder(/uploads)?
At now I'm using:
Code: Select all
plugins.file.writeFile('c:/mymini.jpg',_image.getData())
   var _newFile = plugins.file.createFile('c:/mymini.jpg')
   plugins.file.streamFilesToServer(_newFile,'/mymini.jpg',null)
   plugins.file.deleteFile('mymini.jpg')


But I like to jump the "writeFile" passage and stream the new miniature directly on the server..
My problem is that the miniature is a JSImage object..How can I convert it into a JSFile without write it first?
Marco Rossi
Freelance

Main development environment: Servoy 6.1.6 - 7.4.3, Java 1.6u45,7u71 Windows 7/CentOS
Marco R.
 
Posts: 203
Joined: Thu Mar 19, 2009 12:37 pm

Re: How To use an external image

Postby david » Tue May 31, 2011 10:07 pm

Create a temp file on the client, write the JSImage to that, then stream the temp file. The important code bits:

Code: Select all
var image =  plugins.images.getImage(file.getBytes())
// insert: do something with the image like resize it
var temp = plugins.file.createTempFile(file.getName(), "jpg")
plugins.file.writeFile(temp, image.getData())      
var serverImages = [baseDirectory + directory + "/" + file.getName()]
var monitor = plugins.file.streamFilesToServer([temp], serverImages, IMAGE_import_callback) 
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.


Return to Methods

Who is online

Users browsing this forum: No registered users and 15 guests