I am trying to use the FileReader() function to read a file as text and display it back on my webpage - so far, so good. The problem is, instead of allowing the user to select any file off their computer, I want to offer them a specific list of files on the server, via a drop-down menu.
I have no problem populating the drop-down menu with a list of file names. But what I don't know is how to make the file reader take this file name and read the relevant file. I'm guessing the problem is because the file reader expects a file, and is getting a String, but I don't know how to get round this?
I've spent a couple of hours googling and reading tutorials, and they all seem more or less like this one here, which relies on using an <input type="file" . . .> button.
Can anyone tell me how to do this, or point me to some more extensive/varied tutorials?
Thanks in advance.
Related
After much searching and experimenting, I cannot find a way to programmatically generate an image from a PDF file which contains filled form fields. More specifically, it's not that the libraries I've tried don't generate an image (they do!), but the filled form fields end up blank.
Can anyone point me to a library/solution that works? Ideally in python or javascript, but I'd take just about anything at this point. Ultimately, it needs to end up as an AWS Lambda function.
I'm going to keep trying, but so far PyMuPDF and ImageMagick (ghostscript) don't seem to work, unless there's some options to enable it that I'm missing.
pdf2image (pdftoppm) correctly handles filled form fields. I tested it using this example: https://stackoverflow.com/a/48583124/2009581
I spend a day for digging possible way to manipulate PDF's with forms and still in search. I got PDF, where user can fill some data, save and send to me. The problem is some users didn't know about Acrobat reader and dont't know how to install it. Plus some users are mobile. I try all possible ways - jsPDF lib, FPDF + FPDI, but all this libs work very bad with forms.
Any suggestion how to solve it?
UPDATE. I can't just set php action for PDF form, I also need some action outside PDF.
Finally, I solve this issue. I use php-pdftk class as wrapper for pdftk. This class let me fill form with fillForm(). And I use stamp() and multiStamp() methods of class for add image to filled PDF. I create PDF with image and use them as a stamp.
I've been struggling with this function for a few hours now and I can't get it to work in any way shape or form.
Assume my element location and image path are correct at all times. (Seriously, I've been going over this for the past 4 hours, it's not the element location and it's not the file path.)
What I started with was a sendkeys to the input element. This gave no error but caused the script to hang for ever; it wouldn't get past it and no images were being uploaded.
I literally tried every single possible variation of the sendkeys method listed on the first 4 pages of Google when looking for "Python PhanthomJS Selenium upload file sendkeys". Back to the drawing board.
Currently I am looking into executing a bit of JavaScript through Python to upload the file, though I have no idea how to go about this.
The page which I am trying to upload to has its form set to hidden and only shows a button which opens an upload dialog on normal browsers. I feel this is why sendkeys was not working.
Can anyone give me some input or suggestions as what to try next? Or how to execute some JavaScript from Python?
EDIT:
I learned how to execute JavaScript while using selenium in python and it saved my day.
To anyone coming here from google or whatever with the same problem, let me explain what I did:
The fact that my .send_keys() was hanging when sending keys to the input[file=input] element had me wondering before I made the topic but since the webdriver was still able to find the element I wasn't thinking too much of it and shrugged it off as something random. Later however I came with a suggestion that because it had a css type display: hidden !important the webdriver might have been able to find it, but not interact with it, and for some reason selenium just decided to hang itself instead of crashing / giving an error.
With that in mind I started browsing the docs and found the .execute_script() command, turns out we can use this to run a piece of JavaScript through the webdriver. Why I wanted this, is to see if the class styling had anything to do with it at all, how you ask? Well we can use the following line of code to change the class attribute of the input[type=file] element: document.querySelector("input").className="". This is not the most elegant solution since we are basically deleting the entire class responsible for the display: hidden !important styling. If the class were to hold more important data I'd suggest changing the class instead of renaming it to "" or deleting.
Moving on and trying it out, it showed the input button just like I hoped it would! After this I simply re-tried sending the keys and found no problems at all. There is no need for a click, submit or anything. driver.find_element_by_css_selector('input[type=file]').send_keys('path/to/file') However I did note that the way you structure the path seems to be pretty important. For example I am testing on windows and path/to/file did not upload or select any image for me, using path\\to\\file however, worked completely fine.
tldr:
driver.execute_script('document.querySelector("input")').className=""
followed by:
driver.find_element_by_css_selector('input[type=file]').send_keys('path/to/file')
Is what worked for me, and if you are in any alike situation your
variation on the script should upload the image as intended.
I am working on HTML5 & I am a newbie in it.
I am working on a program which does the following :
I want to drag & drop files on a button.
User will be able to see all drag dropped files.
There needs to be a button to upload files.
After uploading, a progress bar should pop up on which there will be cancel upload & skip (if dont want to upload specific file) button.
Kindly let me know how can I do the same.
Thanks in advance.
if you know a little jQuery you can use jQuery UI droppable/dragable : http://jqueryui.com/demos/droppable/
Here are pretty simple examples for everything you asked : files from input tag, files from drag&drop, printing files names and showing a progress bar. I enjoy that website that makes it easy with the 'new' html5 features.
i am currently trying to add a uploading/scanning screen to my file upload site, (just to be clear i need the 'design' part of it, like actually displaying the box not anything to do with the scanners, or implementing the scanners, just a box that says scanning with a scanning gif next to it). Pretty much my site allows people to upload files which scans them and then displays the result. All the scanners are up and working but i am trying to add this scanning page. I want it to look a bit like this when you upload a file - www.virustotal.com
How would I be able to do this? You don't have to be very specific just like what programming languages, or any examples of code, to help me, i don't really know where to start.
Sounds like you are looking for a modal overlay or dialog.
There are tons of libraries out there that can do this, including YUI and JQuery UI/Plugins.
See my question.