Four Js Development Tools Forum

Discussions by product => Genero BDL => Topic started by: yap b. on April 08, 2011, 10:27:41 pm



Title: base.channel open URL path
Post by: yap b. on April 08, 2011, 10:27:41 pm
Is it possible to use BDL Channel to check whether a file exists (the file path is an URL).

for example:

let str = "http://www.domain.com/collections/12345-01_thumb.jpg"
let ch = base.Channel.create()
whenever error continue
  call ch.openFile(str,"b")
  if status <> 0 then
    display status," - bad"
  end if
whenever error stop

I'm getting "-6340 The channel could not be opened for a file" using the above example
I'm attempting to use openFile to detect whether the file exists in url specified.  Or is there a different method to accomplish the same?

Thanks!

regards,
Bill Yap


Title: Re: base.channel open URL path
Post by: Frank G. on April 11, 2011, 10:03:03 am
Hi, in the Web Service you will find a HTTPRequest built-in class that can solve your issue. For instance you can do something like the following :

IMPORT COM

MAIN
  DEFINE res com.HTTPResponse
  DEFINE req com.HTTPRequest
  LET req = com.HTTPRequest.Create("http://www.domain.com/collections/12345-01_thumb.jpg")
  CALL req.setMethod("HEAD")
  CALL req.doRequest()
  LET res = req.getResponse()
  IF res.getStatusCode()== 200 THEN
    DISPLAY "Found"
  ELSE
    DISPLAY "Not found"
  END IF
END MAIN

Notice that I'm not sure about the status code returned by the server, but it should be something in 2xx.

Regards,
Frank Gross


Title: Re: base.channel open URL path
Post by: Reuben B. on April 12, 2011, 01:03:15 am
Just in case anyone stumbles upon this thread whilst looking for the best method to check if a file exists, this would be the appropriate method to use when you have a standard filename and not a URL ...

https://4js.com/online_documentation/fjs-fgl-manual-html/User/Ext_os_Path.html#FILE_EXISTS