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
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
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