Download an excel file as attachment using Qt browser - qt

I am working on Qt browser(code taken from Qt Tab Browser Example). This Qt browser successfully downloads an image file, but not an excel/pdf file. I need to download an excel/pdf file as attachment on click of a button. Excel generation code at back-end uses PHPExcel to generate and finally saves it using 'php://output'.
On browser side, when I read through QNetworkReply's 'readAll()' function, some encoded string '��ࡱ�' gets printed and nothing gets saved in QFile object, totally empty file.
How do I get the desired excel file from this encoded string ?
Please, any help. It is Linux OS and I use LibreOffice if it matters.

Well, got the answer. I was printing QNetworkReply object's content on the console using reply->readAll() before reading it into the file and Qt documentation states that:
QNetworkReply is a sequential-access QIODevice, which means that once
data is read from the object, it no longer kept by the device.
Therefore, i ended up with an empty file. Found this when i printed the size of the 'reply' object. Also, found some eventLoop related help from here(Roozbeh's answer).
Hope it helps someone else as well. Thanks SO !

Related

mPDF to output a local file + file inline to the browser

I wanna know if i can output a pdf, using mPDF, to a destination as well as a preview in the browser at the same time. ie. I+F at the same time.
I: send the file inline to the browser. The plug-in is used if
available. The name given by filename is used when one selects the
"Save as" option on the link generating the PDF.
F: save to a local
file with the name given by filename
My current code is like this:
$mpdf->Output($OutputLocation,F);
$mpdf->Output();
exit;
It can export the pdf file to $OutputLocation successfully, however, in the browser, it shows:
mPDF error: Some data has already been output to browser, can't send
PDF file
In the documents of mPDF, it has only show one option for one time, any methods to do both in the same output process?
http://mpdf1.com/manual/index.php?tid=125
Please help, thanks.
It turns out that it is an issue on QNAP that their default php.ini is not allowing output buffering.
To solve this, I have edited the php.ini in the WebUI and change the output buffering to 4096. Then it works again.
output_buffering = 4096

Read from bytestream in asp

I'm wondering if it's possible to read from a bytestream without saving it.
I have a file, wich is a PDF that's in a mailbox. Through code I can access this mailbox and read out the attachements in it (the pdf's) At that point every pdf is in a bystream.
For now I just save it locally to test if my code works. But I need to work without saving the file.
Is there a way so I can get data from that file without saving. I need to process the first page and find the image in there (which is a qr code).
I have code to do this from a local file, but I want this to be directly from on of those in the bystreams.
Can I store the bytesteam in something like an object or a list of bytestreams and use that?

How to change an incorrect Mac file's Kind

I have several SQLITE files all of which have Kind set correctly to Document except for one which is Kind = Unix Executable file. It still loads and runs fine. I'd like to clean this up but can't find a way to change Kind for this file to Document.
Anybody know why Kind would have been set incorrectly in the first place and how to change it to the correct value? I've searched here and on Google.
Is there an extension (possibly hidden) set on the file? I think that 'Documents' are merely files without extensions. I'd try File>Get Info on it (via Finder) and checking to make sure there isn't a hidden extension in the 'Name & Extension'
I had the same issue with my php_error.log file. It was "document" and then I foolishly changed the "kind". That mean that the php log wouldn't work and my MAMP server didn't recognise it.
It's still "text document", but to fix the issue I opened up the file in TextEdit, selected "make rich text" under format, saved the file, closed it down, reopened it in TextEdit, selected "make plain text" under format, saved the file and it worked...

Why won't Google Calendar load my dynamically generated ICS file?

I've been given the task of creating an ICAL feed of conference calls for members of our organization. I created a handler in ASP.NET that loops through our database, gets the call data from the database, and creates output that appears valid to me based on what I've read of the ICAL format, and the examples I've seen/disassembled.
Outlook 2007 reads the resulting output and displays the calendar, no problem (screenshot here shows how it renders).
30 Boxes also has no problem with it. (see test here).
But when I try to load the same output into Google Calendar, I get the message "We could not parse the calendar at the url requested":
What's wrong with my output that's causing Google to reject it? You can see the temporary data I'm testing with at this URL: http://www.joshuacarmody.com/temp/icaltest.ics. This is a snapshot of the output from my .ASHX file, unaltered except the phone numbers and passcodes have been sanitized.
Edit with additional Info:
I just tried the following
Created a copy of my test file called "icaltest-1googevent.ics"
Deleted all the VEVENT data from the file
Exported one of my Google calendars to ICS
Copied one VEVENT from Google's exported data into my test file
Attempted to subcribe to icaltest-1googevent.ics in Google Calendar.
I still got an error message. So I'm guessing the issue isn't with my VEVENT data, but with something else about the file. Maybe there's something wrong with my VCALENDAR definition?
the severinghaus ics validator seems to think there is something funny ( a ? ) before the BEGIN CALENDAR
http://severinghaus.org/projects/icv/?url=http%3A%2F%2Fwww.joshuacarmody.com%2Ftemp%2Ficaltest.ics
In my testing google was a lot fussier/rigourous/pedantic - once you get it working with the validator and google it should work in most places.
After lots of trial-and-error, and comparing my output with Google's, I got it working. There were a few problems with my ICS file:
Unescaped characters (I didn't know I had to escape commas!)
Inconsistent line return characters. They didn't show up in my text editor, but I had to use .NET's String.remove() to remove "\r" from my output to get Google to recognize it
The file was missing VCALENDAR:END. Apparently Outlook doesn't much care. Google does.
I had not one, but three funny characters before the BEGIN:VCALENDAR, decimal codes 239, 187, 191.
I found them thanks to the severinghaus.org link above, thanks!
It turns out they're a prefix called BOM in UTF-8, you can read up on it here: http://en.wikipedia.org/wiki/UTF-8#Byte_order_mark
Google doesn't handle this, but after stripping these three characters from the file and uploading to the server, I was able to susbribe to that calendar in Google Calendar (from URL).
I hope this helps someone passing by this page in the future...
I had similar problem until I realised that opening the generated .ics file in Notepad++ wasn't in UTF-8. I was using a method to convert my string to a byte array, but wasn't using an encoder for this, so no matter what content headers I used, the file would never be generated using UTF-8. This simple fix resolved the UTF-8 generation and Google is now happy with my feed:
var utf8 = Encoding.UTF8;
byte[] utfBytes = utf8.GetBytes(myString);
myString= utf8.GetString(utfBytes, 0, utfBytes.Length);

Send file using Response.BinaryWrite() and delete it afterwards

As part of a Classic ASP Project the user should be able to download a file - which is dynamicly extracted from a zip archive and sent via Response.BinaryWrite() - by simply calling "document.asp?id=[some id here]".
Extracting and sending is not the problem but I need to delete the extracted file after the download finished. I never did any ASP or VBA before and I guess that's why I stuck here.
I tried deleting the file right after Response.WriteBinary() using FileSystemObject.DeleteFile() but this results in a 404-Error on the client-side.
How can I wait till the download finished and then do additional actions?
Edit: This is how my code looks like:
'Unzip a specified file from an archive and put it's path in *document*
set stream = Server.CreateObject("ADODB.Stream")
stream.Open
stream.Type = 1 ' binary
stream.LoadFromFile(document)
Response.BinaryWrite(stream.Read)
'Here I want to delete the *document*
I suspect that the point you are calling the DeleteFile method the file you are trying delete is currently locked by something else, the question is what?
Try including:-
stream.Close()
after your BinaryWrite. Also make sure you've done a similar thing to the component you've used to extract the file. If the component doesn't offer any obviouse "close" methods they trying assigning Nothing to the variables referencing them.
Is it not possible to stream the file into memory, then binary write the stream to the browser, this way the file is never created on the server and there is no need to delete it.
I found a solution: The extracted files are saved in a special directory and everytime a user runs the document.asp it checks this directory for files older than one hour and deletes them.
I think it's the simplest way to manage, but furthermore I would prefer a solution where the document is deleted after downloading.

Resources