Error: Cant't find end of central directory - javascript

I am trying to open my base64 file as docx which is created with react-docx library and for that I am using another library react-file-viewer, but I get the following error: "Error: Cant't find end of central directory : is this a zip file ? If it is, see http://...".
I also tried it with react-iframe but unfortunately browsers don't support docx files and it works but it downloads the file instead of displaying. And I need it to be displayed.
This is my code:
<FileViewer
fileType='docx'
filePath={`data:application/docx;base64,${file}`}
/>
If anyone could help me with that. I am looking for the solution for many days and can't find any.

Related

decompressing zipped file in js

I want to have a code where I can unzip a zipped file but even after trying so many things, I am not able to do this.
I want this in my front end because I just want to unzip and process the file inside to do some computation with the data inside.
I tried
https://github.com/nika-begiashvili/libarchivejs
I followed this readme but still i got this error,
https://github.com/nika-begiashvili/libarchivejs#readme
but when I try to unzip the file I get this error
Looking at it, it looks like this error is that it is not able to decompress
i checked another popular solution in StackOverflow this is:
first answer of this:
Unzipping files
but I don't know what is
ZipFile in
var zipFile = new ZipFile(url, doneReading)
How can I get it !!
I am so lost, can anyone please help me !!
This is the zip file that I want to compress !!
This is inside my main zip file:

Three.js - "Unknown format" Error when using .FBX Models

im fairly new to THREE.js. Im trying to load a .FBX Object via the FBXLoader located in three/examples/jsm/loaders/FBXLoader.
Also, i'm using this in React.js.
Now, the page loads but the model isnt there. The error in the console says: An error happened: Error: THREE.FBXLoader: Unknown format.
My FBX File seems to be in binary format, not in ASCII Format.
I really dont know what to do.
My Code:
//deleted
I also tried moving the models folder in and out of the public folder.
Thanks in advance.
I found a solution.
My FBX file had an old version, also it had Binary encoding.
Switching to ASCII and a newer version fixed everything.

File won't save as JavaScript extension in Notepad++

I am trying to use an external JavaScript file in my HTML as follows:
<script src='MyScript.js'></script>
The issue is, I am getting the following error in the Web console:
Loading failed for the <script> with source "file:///F:/GIS%20Assessment%202/MyScript.js".
I have realised that MyScript is not saved as having the JavaScript extension, in my documents it says it's a "File" rather than a JavaScript file. I have tried changing the language to JavaScript and saving as a JavaScript file as soon as I save it in my folder it just converts to a generic file!
What do I do? How do I fix this and save my scripts as JavaScript?
This isn't really a programming question, and is likely to be closed, but to force it to have the extension, simply enclose the filename (with the extension) in quotes.
"MyScript.js"
I know this post is over a year old, but I found it worked when I typed the file extension in capitals when saving the file: "myfile.JS" instead of "myfile.js"

Getting the file extension without knowing it's name

I need to know if there is a way to retrieve the real file extension without parse the filename.
In my code I split the file using the function split(filename, ".") then i get the last element of the array that the function returns.
Now, if I create a .pdf file called, for example test_file.pdf, the previous method works perfectly, but if i rename my file to test_file(without extension) I cannot retrieve the extension even if I know that the file is a PDF.
For example, if i rename test_file.pdf to text_file.jpg how can I recognize that the file is still a pdf and not an image file with .jpg extension?
I would like to know if there is a way to obtain this information, maybe using file metadata or other information related to the file.
I'm looking for a Javascript solution because I have to check the extension when I upload the file using a form (client side) but even a Java solution could be fine, can you help me?
Thank you in advance!
Look at this post and the marked answer: Get real file extension -Java code
I guess it's just what you need.

nXhtml (No javascript-mode/eruby-javascript)

I've just installed nXhtml by downloading their zip file, extracting the archive into my home directory and adding (load "/home/spinlock/nxhtml/autostart.el") to my .emacs file. My problem is that when I try to edit a .js.erb file, I'm getting the error:
(No javascript-mode/eruby-javascript)
and I'm not getting the syntax highlighting that I'd expect (for instance, comments are the same color as javascript code). However, when I move the cursor inside a Ruby section of this file, that notice changes to:
(Ruby/eruby-javascript)
which I take as a good sign plus it does look like I've got the proper Ruby syntax highlighting in this part of the buffer (e.g. comments are show in red font).
I assume that I need to add a configuration file that tells emacs how to manage javascript-mode but I have no clue how to do this. Any help would be greatly appreciated.
Thanks!

Categories