"put binary" command is just outputting text instead of a binary file on LiveCode Server - livecode

I'm using LiveCode Community Server 8.1.2 on Windows Server 2016 Datacenter (running Apache 2.4)
I use the following code
put header "content-disposition: attachment; filename=" & tFileName
put header "content-type: application/pdf"
put header "content-transfer-encoding: binary"
put url("binfile:" & "../resources/documents/" & tActualFileName into tBinaryData
put binary tBinaryData
When included in a script called by a browser this code returns the data as text in the browser window rather than a pdf file that can be downloaded.
A few months ago I wrote this code and it worked, I returned to it today and it doesn't.
I've double checked and I'm sure it's correct but I have no idea what else could have broken it.
I've tested on
Chrome 59 on Windows 8.1 Pro
Chrome 59 on MacOS Sierra 10.12.5
Safari on iOS 10.3.2
Any help or guidance would be most welcome.
Edit:
Network headers from Chrome shown below
Edit:
Amended the code to remove the word "binary" from line 4 - this was generating an error which was producing text output at the end of the returned result - it hasn't resolved the problem - still getting text returned and "Content-Type:text/html" in the response header
Edit:
There are 2 blank lines at the beginning of the source (after using View Source, Ctrl-U on Chrome)

After a couple of days of working on this I now have a solution. It's a work around and I don't know what the actual problem is but for completeness it's worth posting.
The 2 blank lines before the "%PDF" code were the problem and after adding various debugging 'put' statements I tracked the offending code down the the following 2 statements
require ("codeSnippets.lc")
require ("databaseOperations.lc")
Each of these statements added an extra line to the output. I presumed the referenced files must somehow be outputting a blank line which goes unnoticed for a normal html page.
There's no code in them to do this so as a test I added the following code to the very last line of 'codeSnippets.lc'
put "test1"
And I added a similar line between the require statements
require ("codeSnippets.lc")
put "test2"
require ("databaseOperations.lc")
The output showed "test1" and "test2" on different lines. I can't explain what's happening between the last line of the Required script and the next line of the main script. If someone can shed light on this I'd be most grateful.
It's worth noting that I have other require statements that didn't show this issue. The following worked without producing an extra line
require ("../config.lc")
require("../resources/library/templateFunctions.lc")
As a work around I simply moved copies of the various bits of code I need for document download into a new file called "documentHandler.lc" and called the following
require("../resources/library/documentHandler.lc")
It all works perfectly now.

Related

Excel VBA on Mac german special characters not encoded correctly (ÄÜÖ)

I have an Excel VBA Script that I originally wrote for Windows (where it works fine) and now had to port to Mac OS. I don't think that it matters but the script is calling cURL to get a JSON Response from a web API which is then parsed, edited and inserted into the spreadsheet.
Some of the fields in the parsed JSON contain special characters like Ä, Ü, Ö (German characters). The script can handle these just fine on Windows but on Mac instead of ÖÜÄ I get other symbols. This breaks the tool as it depends on some vlookup-functions where the values are written by hand (with the correct symbols).
I tried lots of googling but was not able to find anything.
One thing that might be interesting is that the code itself changes on Mac as well! I have some statements printed to the console and even the hardcoded strings that contain a special character are broken as soon as I open the script on a Mac.
The question is for Mac VBA. This is a pain. The only solution I have is to send the curl output to a file, then open that file with workbooks.opentext and Origin:=65001 and all the response is in cell A1, correctly encoded.
I have asked my own question on that, to see if any one has a more recent answer.
How to read UTF8 data output from cURL in popen/fread in VBA on Mac?

Python script in Colab keeps throwing error message: IndentationError: unindent does not match any outer indentation level

I'm currently using Google Colab in order to take advantage of its free GPU. I was trying to modify a code that I copy and pasted from machinelearningmaster.com. However, whenever I try to add a new code line, for example "print("some words"), I get an indention error.
I have tried adding tabs or spaces before the print call but I still get the error. for example:
space,space,print("some words")
tab, tab ,print("some words")
I have also checked the colab editor settings, currently the indention width setting are set to two spaces.
The first three lines are part of the original code, the print statement is
my addition. I copy and pasted this directly from the colab editor. In Colab all four lines are aligned. As you can see here only the first three lines are aligned. I don't know what's going on.
img_path = images_dir + filename
ann_path = annotations_dir + image_id + '.xml'
count=count+1
print("this is count: ", count)
I expected this to print the value of count, instead I get an error message telling me:
IndentationError: unindent does not match any outer indentation level
Okay, after much searching and frustration, I have an idea of what went wrong, but even better, a solution to fix it.
It appears that the Google Collaborator (Colab) editor does not have a way to set it for tabs "\t" versus space (space-bar entries). From the settings tab on the cell you can set the width of the tab from 2 to 4, but these will be interpreted as 2 to 4 space-bar entries. Usually, this isn't a problem. However, if you're like me and you want to test out code from the web, or be lazy and just copy paste from your editor, problems can arise.
Here's how I fixed it. Before pasting the copied code into Colab, first put it into notepad++. Go to View> Show Symbols >Show All Characters, click on this, you should now be able so see all the characters in the code. Find a tab, it will look like an arrow pointing to the right -->, right click and copy it. Open Search> Find, open the Replace tab. Depending on your version of notepad++ the tab you copied will automatically be entered and the replace will already be set to four spaces. Hit "Replace all". This will automatically replace all tabs with equivalent spaces. Copy the code from notepad++ back to Colab. Now there will be no more conflicts.
I think using a simple find and replace tool will just work fine. I also came across this error recently in Colab and I went through #Rice Man solution. The only difference was I used Libre office writer instead of Notepad++. I also found this tool to be helpful. I am not proficient in using Colab but this solution worked for me.
Another quick fix that worked for me related to this question.
I was trying to run a python script in colab and faced this error though the line seems at an appropriate indentation in that script.
I checked with the !cat filename.py cmd, and found out that the actual indentation appears different than it is in the script (hence the error).
Taking that unindented line (according to the colab) at the start of the line and using space afterward fixed the error.
I used this website to fix the error.
Copy your code to the site, then click beautify button on top left. This will remove indention errors.
If you want to know where the indention error is coming from, use #Prachi answer.

Saving Oracle SQL Developer script as a TEXT file (as in ascii... as in Notepad...)

New to Oracle...
I have a bunch of SQL scripts from SQL Server that I want to edit into Oracle. I load these notepad-capable ASCII text files (ex: myscript.sql) into SQL Developer. When I open it, SQL Developer adds an extra line break between every line I had in the ascii text file. Annoying, but I can deal with that. I soldier on. I edit and change syntax. I run it. It works. I save. I'm happy so far. Feeling good.
But...
Now when I try to open myscript.sql in Notepad, line breaks are gone... there is a blank between every character in a word... it's a mess.
What the heck happened? And how do I make it stop? I know I'm old school, but I like to edit the format of my scripts myself... I want them in ascii text so that I can use a bulk file editor to change things...
I have googled this for a couple hours and have found countless pages regarding saving the OUTPUT of a script as text, but nothing about saving a SQL Developer script as plain text.
Welcome to the world of UNIX vs Windows/DOS line ending differences.
I would recommend using a better editor than Notepad. A modern code editing program will automatically handle the conversion and display.
http://www.cs.toronto.edu/~krueger/csc209h/tut/line-endings.html
So I still don't know how a couple of my scripts got so mangled up, because I can't recreate the issue. Other scripts are editing and saving just fine.
But I did figure out how to fix the couple scripts that did get hosed up.
I loaded Notepad++ for Windows. I opened the offending script, which shows a bunch of [NUL] all over the place. I was able to use the Searce/Replace function in 'extended mode' to search for \x00 (aka null) and replace it with nothing.
Next was the annoyance with line breaks (new line) versus "carriage return plus new line". I was able to use extended search and replace to replace \n with \r\n .
This now got me a file that I could edit in 'regular' notepad. I still don't know where the extra line breaks came into play, but I was able to spin through the file and remove the extra blank lines.
So all is well with the universe again. I got my couple of mangled scripts back in order, and others seem to behave properly now.
Thanks to all for the help. This site has been invaluable to me.

perl5 Number Sign # not working for comments

I have a very strange problem..
perl5 Number Sign # not working correctly for comments..
We use emperl, mod_perl, apache, linux..
In some programs if I have a line commented out with a number sign # or just a number sign # by itself on a line, all of the code below that line doesn't work correctly.
There is a sysadmin so I don't have access or control over any of the settings on the server.
This is a new issue everything always worked previously.
So many possible area's that this might be coming from that I'm checking to see if anybody has run across this..
Any suggestions?
Found the issue:
Was transferring the files from LINUX to Windows to edit them.
If the file was originally created in Windows the end of a line was just a <CR> and for some reason the whole file wasn't running right. It mainly showed up when using the hash symbol for perl comments.
When I made sure the files had end of lines with <CR><LF>, this solved this issue.

Line 1 of txt files being ignored by delphi app, why?

I have a delphi prog that reads from thousands of .txt script files that I have created over some years. I had to do some mass changes so used a search and replace program which in itself took a good few hours! The problem is now the top line of all the txt files seems to be messed up somehow - to me it looks fine however the delphi program doesn't read it and TortoiseSVN records it as a changed line!!
What on earth has happened and how might I resolve it? So far I'm having to delete all the files and remake them. Deleting the line and rewriting doesn't work - even Crtl+A and pasting the old file contents doesn't work! Its as if the header is corrupt?
Could it be a problem with end lines? (windows/UNIX/Mac are different eg \n or \n\r ) use an editor able to show special characters. I think you can with tortoise diff, switching the right option. Else, try with notepad++, for example

Resources