Couldn't really make a descriptive title, so what I'm after is this:
Our users would need to log in to a service they use (it's something like facebook, so they are logged in nearly all of the time), go to a page, select a menu, click on an item, download a file, and upload it back to our site.
What I've tried is to provide a direct link to the equivalent of the export button in the other service, but they have done their job properly, so cross domain requests, etc are not an option - therefore this returns a 400 BAD REQUEST. What I can do is to set up an <a href="link-to-file" download></a> on this element, I trigger a click from our client side javascript, and the users is now able to save nearly all the steps, and just has to reupload the file that has been downloaded.
Now the question: Is it possible that instead of triggering a download for the client's machine, to save the file in memory, to directly upload it to our server?
Or if anyone has any alternatives, that'd be appreciated.
Just for reference, http requests didn't work, as they are signed in to the other app with cookie based authentication, and I don't want to touch that stuff, as It'd possibly give our app permission to act in the name of anyone who clicks a button, and that's not what we're after.
Disclaimer: This might sound shady at first, but we are really just trying to save steps for the less tech-savvy users, so they could import their already existing data easier.
What I can do is to set up an <a href="link-to-file" download></a>
ok so this is what i understood.
you are trying to put a download button or something like that.
i think you can do it this way:
since you have the link to the file_to_download_link (link_to_file)
when the user clicks the download button or link, send the link_to_file to the server with ajax. and in server you can download the file or do what ever you want with the link. (you don need to upload it again. just download)
Related
I am trying to figure out if it is possible to click on a button on the Amazon website from outside of the website.
For Example: At the bottom of every product review is a "Helpful" button. If a review was helpful, the reader/shopper can click this button to let the reviewer (and Amazon) know that the review was helpful. (It's basically a "Like" button).
What I'm trying to accomplish:
I want to post my reviews on my own website/blog and still obtain "Likes" without asking readers to click a link to a product page, then search for my review, then click the button.
You probably won't be able to do what you have in mind.
JavaScript can generally access information on another domain except if specifically configured in the origin website through CORS. Unless you own amazon.com, you won't be able to configure amazon's CORS headers to make them accessible to some JS running on your website.
You can however, from your website front-end, make a request to your website back-end that would be able to access amazon's data just like your browser does. Using a browser emulator like Puppeteer, you'll be able to launch an amazon page and programmatically retrieve infos, click on things and do other stuff.
However, the page that Puppeteer will be able to spin up will include credentials (cookies, localstorage content, auth token, etc) provided by your server, so Puppeteer will not see the same amazon.com your user sees on his browser, unless your user agrees to give you its amazon credentials, and at this point I'm pretty sure no user would do that, and that would not be authorized by amazon's terms of services.
TL;DR even if what you have in mind is not impossible, it would weeks for your and your team to code a system that would potentially allow you to do that, and that's provided the law is on your side, which is probably not the case.
I'm trying to make a comment section for a locally hosted site, basically I am trying to make it so when you hit the submit button, it checks for a existing file, if it exists, then it will edit it, and put the comment into it, if it doesn't exist, then it'll create the file, and save the data, I'm trying to save it as JSON if possible, any ideas?
The only things I can find are to let the visitor save to the computer, which isn't what I'm trying to do, I want the site to only be able to access it. And I'm trying to not set up a server if possible.
You will definitely need some kind of backend server to do that since JavaScript runs on the client side. I can only recommend taking a look at a NodeJS http server that changes the files according to GET or POST requests or using said GET and POST requests in combination with a server-side PHP script.
I'm having a hard time figuring out how to approach file uploads in atom electron. I would post code but I don't even know where to begin with this one.
In a standard web app I would post from the client to the server, either via a standard postback or using an ajax request. I have some pretty cool solutions for that. But in the case of electron, I'm not sure where or how to "post" the file back. I guess I just want to access the contents of my <input type='file' /> from node.js. How do I do this?
I could post to the browser process, but I don't know what the "address" would be. Or do I need to create a separate "page" in my app just to accept form posts? My background in web-dev is probably blinding me to some obvious answer, can someone help?
EDIT
Just to add a little more context, I have a .csv file which I'd like to allow the user to upload. I will then process this using node-csv and insert each returned row into the app's nedb datastore.
If you're going to process the file on the user's machine then there is no need to upload the file anywhere, it's already exactly where you need it. All you need to do is popup a dialog to allow the user to browse their file system and select the file they want your app to process. You can create a button and call dialog.showOpenDialog when the user presses it, that will get you a filename and you can then use Node's fs.readFile to read it from disk, then you can go ahead and process the contents in whichever way you want.
Is there any way to detect if a user has selected ok or cancel to download a file in JavaScript? For instance if I have a link that points to a file and a user clicks on it download that will automatically start the download of the file, but how do I know if the user has been prompted to do download or not?
If they've clicked on it you can be pretty sure they'll be prompted to download it. To find out if they've downloaded it though, you'd need to implement that on the backend. There is no way the webpage itself will be able to know.
On the backend you'd have to monitor the communication with the client via the web server and see how much data has been transferred to the client and compare that with the total size of the file.
You could then make this data available on the server and using some sort of XMLHttpRequest or websocket, the page could update with a progress bar if that's what you're looking for.
I have a online web application form which I have to open every time and have to fill data and Submit.. So, I have got an idea of making a Google Chrome extension, that will make that page stored inside localStorage So that I can access it like a desktop page.. Is this possible.. I do not have any permissions to change the web site at server side.. I am just a client side programmer.. Is it possible? if yes please let me know how can I achieve this..
in theorie, yes, you could. Practically, it won't work out like you want. The reason are the external resources the website is going to be needing.
Storing just the html (document.body.innerHTML) would be possible. BUt if you want the formatting/layout to be happening, you'd need to save the computedStyles for each element as well. And if an image, you'd need to Base64 encode the image and save it.
Even if you'd succeed in saving the page, you'd need to know when to expire your localStorage cache and refetch the resources to stay compliant to the server side parsing of the form data (if they'd change something).
if its just about submitting a form, you also could just trigger the forms post-action-url directly by writing a script that resends the data you want sent.