I'm new to React Js and i'm trying to print a file from a url using printJS.
My intention is to access the DB and get a url of pdf file to print, and then print it (without opening a new page if possible).
For testing, after returning with the url i'm just trying to print a local file and not the url given from the db(I assume there might problematic due to security issues, CORS, etc.)
After importing the library into the project i'm trying to do:
printJS('path/to/file/a.pdf');
I don't get any error, and it seems nothing happens, except this warning:
Resource interpreted as Document but transferred with MIME type application/pdf: "blob:http://localhost:3000/18bdc43e-6b53-47ea-91e4-bb62ad76dcc6".
The file exists and when i'm using the url bar and putting path/to/file/a.pdf, i'm able to access the pdf.
https://github.com/crabbly/Print.js/issues/176
Looks like you need to use a domain url instead of a local file path.
Related
When I run the Python file, the file works correctly, but when I run the Python file with the script, it gives an error in read txt file(file not found).
how can i solve this problem؟
Software written in any language (Python, JavaScript, WASM) cannot access local files directly. This is a browser security restriction. The browser can access files on behalf of your application using the <input type="file"> DOM element link.
In Python and JavaScript, you must provide the user with a file input selector. The user selects the file and your application can the retrieve the file data from the browser.
In JavaScript this functionality is implemented with the FileReader class. This class can be used in Python via the create_proxy() function to proxy event callbacks.
If you are just getting started with Pyscript, I have written a number of articles link.
See this issue report.
Code running in a webpage is sandboxed and can't freely access files on the computer hosting the browser.
(It would be a terrible security problem if just visiting a webpage would give the author of the page access to your files).
If you want to access a file on the user's computer, use <input type="file"> and have the user select it. I don't know if you can access it directly or if you would need to use a JavaScript FileReader and then pass the results from JS to PyScript … but one of those two approaches should be possible.
I have a file path in my react website and want to get the contents from that file.
I have tried the fs readFile but it just gives me TypeError: Object(...) is not a function. I'm not sure that's the way to go.
I have done some searching but I'm very new to react and javascript so I haven't found anything.
Here's my code
import { readFile } from "fs";
...
readFile("../../../" + filePath,'utf8').text}
where ""../../../" + filePath" is a relative path to the markdown file I want.
I expect the readFile() to return just a string that looks something like
Hello!
This is **markdown** text
in one string but right now it just gives me the error I gave above as soon as it's run.
The fs object exists in Node.js, and React is a browser framework. You can't read a file from the filesystem in the browser - that would be a security problem.
Instead, you probably want to issue an XMLHttpRequest to fetch the content from the server at which point you can manipulate the content in the browser context.
You can't open a file in javascript that runs on browser's side. This will be a security issue, coz everyone will be able to write scripts which will get all the files from the user's filesystem and push them on some server.
The readFile() directive comes from nodejs, so if you have a nodejs server which represents the backend than you will have the posibility to open/read and write to file.
I'm implementing an application using react-filepond where once the user selects/drops the files, i need to get uris (for the files) for upload from an endpoint(server), and then using those uris to upload to our storage.(whilst also showing upload progress to the user)
is using onupdatefiles prop to send getURIs request and then using onprocessfile/onprocessfilestart to upload those files using the retrieved URIs, the best way to do this?
also what is the use of the progess parameter we get in the onprocessfileprogress(file,progress)? can it to be used to feedback the progress back to filepond component?
I think you can implement a custom server.process function and handle all upload logic in there, wether uploading to your local server of first uploading to a remote server it should give you enough control over the entire process.
https://pqina.nl/filepond/docs/patterns/api/server/#process-1
For our project we've been using a lot of subdomains, but for one particular section we just use a redirect that sends the user of a specific type from the normal dashboard at /dashboard to /manager/dashboard.
This has been in place for months and works, but now in an element within our view we're trying to load some scripts using the HTMLHelper, but it's appending the /manager to the URL.
How can I have it just access the webroot version at
/js/path
instead of
/manager/js/path
using a generic element that is used throughout our application in different subdomains like it doesn't now (with the exception of /manager/*?
Try adding
Configure::write('App.jsBaseUrl','js/');
to your bootstrap.php file.
Alternatively, if you provide the full path to the .js file (starting with a leading /), CakePHP will ignore whatever App.jsBaseUrl holds, and will render the correct path.
I was wondering if there is anything wrong with using html and php files without extensions.
For example, if I was to upload a file with an extension, I would get to by using a URL like this:
http://yoursite.com/randompage.html
If I used a file without an extension, I would use a URL like this:
http://yoursite.com/randompage
I know that this can't be the preferred method because it leaves the file without a way to be identified, but is there anything that would stop the site from working properly?
What you want to do is done with url-rewriting .
Basically, you will add a rewrite rule to your web server, so when he receives a request for url yoursite.com/randompage he will change it to yoursite.com/randompage.html. You will find a lot of examples on the web if you google for "mod_rewrite examples" or "url rewrite examples".
Document types are sent from the webserver in http headers, so it is perfectly possible to do what you are asking.
For instance when using Apache, to tell it that any file with no extension is html, in the 'conf' file you can say:
DefaultType text/html
More details at Apache The Definitive Guide
This point to concrete document (randompage.html in this case):
http://yoursite.com/randompage.html
This point to default document in directory:
http://yoursite.com/randompage/
Default document is set in you webserver. This could be for example: index.html, default.html, index.php, default.apsx,...