Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: base.channel open URL path  (Read 9110 times)
yap b.
Posts: 17


« 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
Frank G.
Four Js
Posts: 48


« Reply #1 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
Reuben B.
Four Js
Posts: 1048


« Reply #2 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


Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines