JSZip unzipping error - javascript

Trying to handle with JSZip library.
I am having an issue to unzip a file. Here's a plunker demo. As you can see I can successfully zip a content, but when I try to unzip a zipped content I get an error (can be seen in console):
Uncaught Error: Corrupted zip : can't find end of central directory
Any ideas why this happens?
In any case, here's what I am trying to achieve: I have an textarea on my page. Upon click I want to zip textarea content and send zipped data to server. Another call must be able to receive a zipped data, unzip it and replace textarea text with unzipped one. Everything works ok, except unzipping problem.

The generateAsync() method defaults to a base64 output but the loadAsync() method only see a string.
You have two solutions :
change the generated format with `generateAsync({type:"uint8array"}) (see here)
or tell the load method that you are loading base64 content : loadAsync(data,{base64:true}) (see here)

As answered by David has resolved my problem on my local workstation running Windows 10 OS. However it is failed on the Server running RHEL OS.
I have to fix it by switching to yauzl package for unzipping. It is recommended as mention on package's official repository, with specified merge pull 383.

Related

Pdfmake Uncaught invalid image error even with correctly url

When I try to download PDF file with image generated by pdfmake I got:
Uncaught invalid image, images dictionary should contain dataURL entries (or local file paths in node.js)
I have visited playground on their website but I got there the same error.
Here I paste the example url to image generated by my server. It works fine as you can see (paste it to the browser url).
Finally I posted code:
pdfMake.createPdf({
content:[{image: 'url from paste bin here'}]
}).download();
Honestly I have ran out of ideas.
You can include local JPGs and PNGs from your filesystem if you put them in the ./images folder from the pdfmake root. Then they will be referenced as "./images/filename.jpg" (or .png as the case may be). [EDIT: Also, images won't load above a certain filesize in preview. They will still work on server side rendering. I had a 4.7 MB PNG that would render just fine server side but no matter what, can't get it to render on the client. So just be sure to be using small images if you want to use the dev playground clientside preview feature.)

TinyMCE Javascript File 500 Internal Server Error on Production Server

I have a website made with CakePHP, with a plugin I made modified from CakeDC TinyMCE plugin
This all works well on my development server, but when I upload to production (HostGator) the TinyMCE textareas do not load correctly, and the Console shows X GET .. path_to_TinyMCE_JS_File.js
My other plugins work fine so not a plugin loading problem
I know I have the paths etc correct as when i load a test.js file into the same folder and navigate to that I can see that file contents
When I navigate to the js file, I should be able to see the JS text, but it 'renders' as an empty file/blank page. In the console it tells me I have a "500" Internal Server Error
I have re-uploaded the JS file and it seems like it should be fine (right file size etc). Permissions seem okay (0644).
I'm using TinyMCE 4.0.26 (I did try uploading the latest TinyMCE JS and got the same 500 error) via the CakeDC TinyMCE CakePHP Plugin, CakePHP 2.3 (I think..)
I'm not sure what to try next, any help much appreciated
if you are getting a 500 error, the only logical thing to do is checking the error logs on your server. The location of logs changes depending on your web-server software and os. But by default on linux/apache you can find your error logs under /var/log/apache2/ if you open up your related error log with;
tail -f /var/log/apache2/[your-site-name]-error.log
then simply refresh the page from the browser to see the latest logs of errors. That way, you will be able to identify the problem. If you cant identify it yourself, just copy/paste the error here.
Yay, have finally found the solution here!
The problem here is that in HostGator php Short Tags are on by default. There is a
I had to modify my php.ini file on HostGator to turn off short tags, all good now!
This post is what got me over the line:
Why is the JavaScript file parsed as PHP in my Cake plugin?

how to get pdfJS to render a pdf from URL?

i am using PDFJS to render PDFs files using their URL after scanning the current page a js snipet return the urls. then it passes them to pdfJS. until now everything works the problem show when the PDF is already open in the browser . i take the URL (*.pdf) and pass it the same way as before the difference is that the file is not downloaded and i have this response.
Warning: Unhandled rejection: Unexpected server response (0) while retrieving PDF "http://geekographie.maieul.net/IMG/pdf/progit.fr.pdf".
(just for the record i dont have CORS issues).
Try this "http://mozilla.github.io/pdf.js/"
Installation
download and unzip file.
put "PDF" file in this folder.
config in "viwer.js", edit var DEFAULT_URL.
upload folder to server.
Have fun!

File Exists But Receiving ENOENT Error

Here is a gist: https://gist.github.com/973e70bde8e6a530c489
I have two scenarios. One works and one fails even though the code is exactly the same.
Take a CSV file already on the box and parse it. Works perfectly. No issues.
Take a CSV file that was just created and attempt to parse it and I receive:
ENOENT, no such file or directory '/Users/Home/dev/csv/TwFrI5vhdownload.csv
Same CSV file format and all that. Wouldn't matter anyway because the created file won't even open. It fails with the error above even though the file does exist. If I restart Node and attempt to grab that file, then it works perfectly. If I run fs.stat on the newly created file it fails.
I've tried timeouts, external callbacks, etc.. but with the dynamically created file it always fails.
What am I missing here? Is the file locked and I don't know it?
Thanks!
System:
OSX Lion
Node v0.6.7
Are you sure the file is actually created when you try to parse it?
I took a look on the gist and I guess you are downloading the file from somewhere and then parsing it. Without the whole code I can only guess, but I think that you started the download, but you haven't received a clear indication it is there and ready to be parsed.

Xml to js code problem

So i'm very new to xml to javascript so i thought I would learn from w3schools, but this site
http://www.w3schools.com/xml/xml_to_html.asp shows an example that I can't mimic locally. I copy/pasted the .js and downloaded the xml but I just get a blank screen!
It's working in there try it yourself but not for me? Do I need it on a server or something?
Yes, that code retrieves the XML data from a web server using AJAX. Since you don't have a server running locally, you can change the URL to point directly to the w3school's version:
xmlhttp.open("GET","http://www.w3schools.com/xml/cd_catalog.xml",false);
Alternatively, play around on their online version ;)
well i guess you have to add the example xml (cd_catalog.xml) to your file system. and you definitively have to access the html file on a server (apache i.e.)
First, ensure that both HTML file (with the Javascript block in it) and XML file are placed in the same directory.
Next, you probably need to place those files under your local web-server and open the HTML like this:
http://[local server host]/ajax.html
instead of opening the file directly from e.g. Windows Explorer:
C:\[path to the file]\ajax.html
For the latter case you'll get an "Access is denied" error.
-- Pavel
Are you running this under a web server or just creating a couple of text files and loading them in your browser?
The "GET" request this relies upon could possibly be failing.
Use Apache or another similar HTTP server and run the example as if it were hosted on the web.

Categories

Resources