Uploading file using ajax (without FORM) - javascript

I have some files in the local and know the path of those files.
I'm trying to upload the file using AJAX.
How to upload the file using AJAX without using FORM.
enter code here
NOTE: I've the FileReader object of the file.
Please share if u have any idea.
Thanks

You cannot upload a file from the local computer unless triggered by the user (the user should select the file), you can upload a file with jQuery:
https://github.com/blueimp/jQuery-File-Upload
https://github.com/hayageek/jquery-upload-file

Related

Avoid file uploading in Dropzone.js - interested in JSON contents in browser

I'm using Dropzone.js to allow a user to upload some .json files to a web app. These json files are then parsed and used on a different page.
I've got this working using the 'addedfile' event and a FileReader() object.
However, I would like to avoid dropzone trying to upload the files and making a failed POST call to '/undefined'.
How could I achieve this?
Thanks!
You need to set autoProcessQueue dropzone option to false. With autoProcessQueue set to false dropzone will not upload files independently. Check Dropzone.js documentation for more details.

Download file from url and then upload to another site via js

I have a requirement to download a file from a url, then POST it to another site via single js call.
Use case:
User enter a file URL then click Re-Upload button
Conditions:
The file will be either audio/wav, audio/mp3, or a zip file with multiple wav and mp3
I need to POST using multipart/form-data
Questions:
How do I create multipart/form-data request via js manually?
Correct me if I am wrong, but I think I need to store the file content into an input field once I download it.
How to encode this file content into a string that will comes up as byte[] when uploaded?

keep file order using jquery file upload

I was looking at the upload script here:
http://demo.tutorialzine.com/2013/05/mini-ajax-file-upload-form/
It is using jquery file upload to upload multiple files at once. I would like to know how to pass the order of the files that were selected to the upload.php script. ie. if you have 1.jpg, 2.jpg, 3.jpg, 4.jpg, and 4 finishes uploading first, can upload.php receive a variable that tells it that it is the 4th image that was selected? Does jquery file upload have a way of adding the order to the form action perhaps?
Thanks in advance.
It should automatically upload and read the data in the order it was received once it hits the upload.php layer. So just make sure you upload the files in the order you want them.
Well it was a really easy fix once I found it. There is a variable in the jquery.fileupload.js file called sequentialUploads. Set it to true, and it will force the order of uploads to be the order in which the files are selected.

Showing a bootbox.js dialog to make a selection during dropzone.js form action while sending to node.js server

I have a node.js/express site which has an upload dropbox which use dropzone.js to do drag and drop uploads. My dropzone inside my jade template looks like this currently:
div(id="dropzone")
form(method="POST" action="/upload" class="dropzone" id="my-dropzone")
div(class="dz-message")
span Drop your zipped AgentCubes project here to upload it
This currently works fine, but in the case where the user uploads the same file again I would like to provide the option to overwrite the old file or generate a new name for the duplicate upload. This would not work with my current scheme which simply sends the file /upload which is an express endpoint I have created which currently handles the upload.
It is also complicated by the fact that I would need to post to the server to decide if the file is a duplciate upload, then show the bootbox.js dialog in the client and then finally send the upload data to the server. I have looked through the dropzone.js documentation but I can't seem to find anyway to accomplish this. How can this be done?

Getting the all files in .zip file while uploading files

I'm trying to use uploadify control in MVC3. It works fine for uploading files.
Here is my problem:
How can i get the files in .zip file ?. Let me clear the question.
Here is a zip file (say : images.zip). It contains 3 jpeg files.
Now if i upload the images.zip file using upload control on my view page i need to get all the image files in the zip file.
If i uplaod images.zip file it should show all the images like this
I dont know how to get the files and how to start.
I've searched google but didnt get any clue about this.
How to get this? If any Jquery or Javascript code is avaliable please post.
If you can use .NET 4.5, there is a new ZipFile class that will let you get properties of a zipped archive.
If you're under 4.5, you will need a 3rd party zip file library, like SharpZipLib or DotNetZip.

Categories

Resources