A very niche question, I know.... Any probably one for @thebearmay more so than anyone else, but given the time difference thought I would open it up to others.....
I am trying to setup a driver that downloads and stores a HTML file locally on my HE hub, where that HTML file also includes some javascript that itself stores both a json file and a CSS file. No prizes for guessing the context of what I am trying to do.... ![:slight_smile: :slight_smile:](https://community.hubitat.com/images/emoji/apple/slight_smile.png?v=12)
I'm assuming the issue is the collection of backticks or maybe even the content-type I am using.... (text/plain). I'll post some more details later.... Just was curious if anyone else had done something similar and had any tips....
Need to remove all \r and \n at a minimum but probably a few others as well if you’re looking to put into local storage.
Ok, thanks, thought I had it for a while just recently, using plain text and the text parser, but the first it seems to have cut it off at the first backtick. I'll try removing the line feeds and carriage returns.
Easiest way is to write it a line at a time.
1 Like
Ok, I might parse it a line at a time rather than one long string.
Hang on, write it a line at a time?
At a minimum it should isolate the characters at issue that way; i.e the append function.
It's possible the first backtick that is followed by a carriage return might be messing it up.... I'll try putting a space after the backtick... Nope....
It really doesn’t like much below 0x20, should be okay 0x20-0x7e if I had to guess.
???? So Unix vs Windows line feeds / carriage returns?
ASCII Special characters seem to make it choke.
Hmmm... weird. I can upload the file fine via File Manager, just when I try to download the raw copy via GitHub using a driver.... Could it be UTF-8.... Probably not, Notepad++ says I am using UTF-8 and Windows (CR LF). I'm also using UTF-8 in the HTTP calls to Git....
File Manager is able to use the form upload natively, we’re doing the same thing but through the side window. I may have some time to play a little this mornin’, if so I’ll see if I can get some code together to read from a raw page and place into File Manager.
Thanks, really appreciate it.
If you have a sample in mind PM me the URL and I can make sure whatever I come up with works for you.
All good, happy to post the code, give me a minute...
Funny.... The backticks don't seem to show in the post. Let me upload the driver to Git....
void downloadEditorHTML() {
String uri = 'https://raw.githubusercontent.com/sburke781/hubitat/SimpleCSSEditor/SimpleCSSEditor/SimpleCSSEditor.html'
def params = [
uri: uri,
contentType: 'text/plain; charset=UTF-8',
textParser: true,
headers: [:]
]
try {
httpGet(params) { resp ->
if (resp != null) {
String data = resp.data.text;
writeFile('SimpleCSSEditor.html', data);
}
else {
errorLog('Null Response')
}
}
} catch (exception) {
errorLog("Read Error: ${exception.message}")
return null
}
}
Boolean writeFile(String fName, String fData) {
try {
def params = [
uri: 'http://127.0.0.1:8080',
path: '/hub/fileManager/upload',
query: [
'folder': '/'
],
headers: [
'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryDtoO2QfPwfhTjOuS'
],
body: """------WebKitFormBoundaryDtoO2QfPwfhTjOuS
Content-Disposition: form-data; name="uploadFile"; filename="${fName}"
Content-Type: text/plain
${fData}
------WebKitFormBoundaryDtoO2QfPwfhTjOuS
Content-Disposition: form-data; name="folder"
------WebKitFormBoundaryDtoO2QfPwfhTjOuS--""",
timeout: 300,
ignoreSSLIssues: true
]
httpPost(params) { resp ->
}
return true
}
catch (e) {
errorLog "Error writing file $fName: ${e}"
}
return false
}
I’m thinking that if we process it like the old StringReader StringWriter days it should work; i.e. read the raw file into a buffer area, and then write it back out a line at a time. So an asynchttpGet on the raw file, grab the response, and split on \n or \r\n and then use the append to write it to File Manager.
Ok, worth a try. I'll have a go....
Here's the link to the html and the groovy driver:
1 Like
I don't see any description of the problem or logs in this thread.. are you getting errors from the file manager or the javascript?