Download attached file - javascript

Is there a way to download files attached using Paperclip without using libraries?
My goal is to allow the user to download the file as soon as the file is uploaded and before it is sent to the backend.
I found the way to make it working with file-saver
However, I was wondering if that can be done without the library?

You can use the js-file-download package.
https://www.npmjs.com/package/js-file-download

Related

How to download pdf file using vuejs and bootstrap-vue

I'm trying to upload a pdf file to my browser, but I want to be able to download this file afterwards. I am having problems on the second task - downloading it.
I'm uploading as follow:
<b-form-file v-model="form.file" :state="Boolean(form.file)" placeholder="Choose a file..."></b-form-file>
How can I download form.file content after upload is done?
Edit:
I found this API, which handles file downloads nicely.
You need to save the file somewhere on your server or on a storage service (ie Amazon S3) and then redirect the user to a link where the file itself is served.
The specific implementation is based on your backend implementation and your architectural choices.

Html 5 file upload and how to send a file from a browser to backend

I've seen a few tutorials of how to use Html5 File API such as this https://www.html5rocks.com/en/tutorials/file/dndfiles/ for file uploading. What I want is a few pointers of how to send all that from a browser to backend and process it there to actually upload files. In those tutorials it's not shown.
The backend language doesn't matter.
And I don't want to use an external js library, only pure javascript.

Upload files using angularjs without php script

just want to ask if it is possible to upload files (images, docs, pdf, etc.) using angularjs without actually using php script, instead all file uploads will use angularjs or javascript codes?. With this method i will be able to lessen the server load. Thanks
That is not possible.
AngularJS is solely a frontend framework. In order to upload something, you need to communicate with a server.

File download using JavaScript and servlet

I have made the servlets both to download and upload the file independently.
Now I need to write a JavaScript code such that as soon as I upload a file a link appears in another HTML page to download that file.
you can use AJAX to upload the file and then generate the response to get information about your file to create a link for it. I used the following jquery plugin to implement it.
Java Form Plugin

PhantomJS - Upload a file without submitting a form

Is it possible to upload a file to a certain page using PhantomJS without submitting manually the form? I think something is possible using the Content-Type: multipart/form-data.
The example on https://github.com/ariya/phantomjs/blob/master/examples/imagebin.js is working fine, but I want to send directly the file in the POST request without interacting with any element.
Any suggestion?
Thank you very much
File uploads can be done over AJAX (as of xhr2 - if you need to support older browsers, use something like jQuery-File-Upload; there is a good tutorial here on using it just to do the upload part, and not using Blueimp's UI.) That is related to the "without manually submitting the form" part of your question. You will still need to interact with a file upload element to choose the file, and that is where you use page.uploadFile().
To do it solely from JavaScript, without "interacting with any element on the page", you could use page.evaluate() to run some custom JavaScript. It could then use the File Reader API to find the file on local disk, store it in a blob, then upload that blob over AJAX. The WebKit in PhantomJS (roughly equivalent to Chrome 13) should work, as apparently the FileReader API has been there since Chrome 6.
(BTW, if all you wanted to do is upload a file to a server using a headless script, PhantomJS is overkill, and you could use curl. But I'm assuming you want to use PhantomJS for some other reason!)
The solution I've used at the end is a mix of NodeJS and PhantomJS, in case I need to upload something I fork a process and upload the file(s) using the NodeJS "request" module and then send back to PhantomJS the output of the page, which need to be manually processed.

Categories

Resources