Comments on: Drag and Drop and Automatically Send to the Server https://stevefaulkner.github.io/html5doctored/drag-and-drop-to-server/ helping you implement HTML5 today Thu, 28 Jul 2016 17:36:34 +0000 hourly 1 By: ducle https://stevefaulkner.github.io/html5doctored/drag-and-drop-to-server/#comment-1828606 Fri, 03 Apr 2015 03:26:34 +0000 http://html5doctor.com/?p=4500#comment-1828606 This source code not work on google chrome. e.dataTranfer.files.lengh = 0. How can fix this bug???

]]>
By: Jon Squire https://stevefaulkner.github.io/html5doctored/drag-and-drop-to-server/#comment-1125785 Wed, 03 Dec 2014 03:14:24 +0000 http://html5doctor.com/?p=4500#comment-1125785 Rather than drag and drop, can you make
file upload work on Linux from user selecting file from
a directory?

Upload Files using XMLHttpRequest – Minimal

function fileSelected()
{
var file = document.getElementById(‘fileToUpload’).files[0];
if (file)
{
var fileSize = 0;
if (file.size > 1024 * 1024)
fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString\
() + ‘MB’;
else
fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + ‘KB’\
;

document.getElementById(‘fileName’).innerHTML = ‘Name: ‘ + file.name;
document.getElementById(‘fileSize’).innerHTML = ‘Size: ‘ + fileSize;
document.getElementById(‘fileType’).innerHTML = ‘Type: ‘ + file.type;
}
}

function uploadFile() {
var fd = new FormData();
fd.append(“fileToUpload”, document.getElementById(‘fileToUpload’).files[0])\
;
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener(“progress”, uploadProgress, false);
xhr.addEventListener(“load”, uploadComplete, false);
xhr.addEventListener(“error”, uploadFailed, false);
xhr.addEventListener(“abort”, uploadCanceled, false);
xhr.open(“POST”, “UploadMinimal.aspx”);
xhr.send(fd);
}

function uploadProgress(evt)
{
if (evt.lengthComputable)
{
var percentComplete = Math.round(evt.loaded * 100 / evt.total);
document.getElementById(‘progressNumber’).innerHTML = percentComplete.toS\
tring() + ‘%’;
}
else
{
document.getElementById(‘progressNumber’).innerHTML = ‘unable to compute’\
;
}
}

function uploadComplete(evt)
{
/* This event is raised when the server send back a response */
alert(evt.target.responseText);
}

function uploadFailed(evt)
{
alert(“There was an error attempting to upload the file.”);
}

function uploadCanceled(evt)
{
alert(“The upload has been canceled by the user or the browser dropped the \
connection.”);
}

Upload Files using XMLHttpRequest – Minimal

Select a File to Upload

]]>
By: harshitha https://stevefaulkner.github.io/html5doctored/drag-and-drop-to-server/#comment-203031 Thu, 07 Aug 2014 13:46:35 +0000 http://html5doctor.com/?p=4500#comment-203031 Sir can u please help me in getting full path of the image/file being dragged and I am not using any server to do this. It has to be completely client side, I browsed through Google but all my effort went in vain because all I could get was only the name of the image/file but not full path. Please can you tell me how to get the full path of the Dragged image, since it has to be stored somewhere when it is being dragged.

Thank you

]]>
By: Aish https://stevefaulkner.github.io/html5doctored/drag-and-drop-to-server/#comment-44383 Tue, 14 Jan 2014 10:18:11 +0000 http://html5doctor.com/?p=4500#comment-44383 Sir,
Please tell me how to arrange images horizontally when we r dragging them.

In example they are getting arranged vertically.

I wan to make horizontal tile.

]]>
By: Ian Yang https://stevefaulkner.github.io/html5doctored/drag-and-drop-to-server/#comment-37612 Wed, 28 Aug 2013 04:16:51 +0000 http://html5doctor.com/?p=4500#comment-37612 It turned out to be the file size limit in the php script which caused the issue. Thanks all. No action needed.

]]>
By: Ian Yang https://stevefaulkner.github.io/html5doctored/drag-and-drop-to-server/#comment-37610 Wed, 28 Aug 2013 02:46:42 +0000 http://html5doctor.com/?p=4500#comment-37610 I used the php script here, but can’t see the uploaded file in the /upload folder.

I changed XHR request to upload.php in the js code. And the progress can go to 100%. But I just don’t see the uploaded image in /upload folder.

Could anyone help? Thanks.

]]>
By: Yohn https://stevefaulkner.github.io/html5doctored/drag-and-drop-to-server/#comment-37245 Mon, 05 Aug 2013 20:29:24 +0000 http://html5doctor.com/?p=4500#comment-37245 for multiple file upload I changed one of your lines in the javascript -> formData.append(‘file[]’, files[i]); <- added the [] in the statement and I was able to get the multiple file uploads to work correctly :) Thanks for the script! its awesome

]]>
By: Hershel Pearl https://stevefaulkner.github.io/html5doctored/drag-and-drop-to-server/#comment-36841 Tue, 23 Jul 2013 19:54:59 +0000 http://html5doctor.com/?p=4500#comment-36841 Remy,

Could I use this to D&D routine to drag (copy or cut(?)) a record that was acquired from the database, from a column to another column, then with a webmethod postback the update/change to the server’s database, then update the client with the results?

]]>
By: Chintan Patel https://stevefaulkner.github.io/html5doctored/drag-and-drop-to-server/#comment-35097 Fri, 14 Jun 2013 14:25:37 +0000 http://html5doctor.com/?p=4500#comment-35097 Hi Remy,

I am working on java – spring mvc. I am submitting my data through JSON.

What I want to do is:
I want to upload an image instantly in to temporary folder on my server using , and show what is to be uploaded.

On final submit all data including uploaded image path (temporary folder’ path) will be passed to my spring controller through JSON object, then transfer image from temporary directory to actual directory & saved all data in to a database.

There are few questions:
1. Where the file is to be uploaded (location)?
2. Where to give folder path?

I would be appreciated if you can hep me.

Thanks in advance.

]]>
By: Greg https://stevefaulkner.github.io/html5doctored/drag-and-drop-to-server/#comment-34688 Mon, 27 May 2013 17:10:53 +0000 http://html5doctor.com/?p=4500#comment-34688 Wanted to pop in and thank you for a great start you gave me; I took it a different direction and thought that your readers might be interested:

– The files list is inside the event, so if you don’t need to pass it into formData, you can post each individual file and get information from each file’s xhr2 object. This will allow you to do things like per-file progress updates. So, instead of pushing into the formData object, you can just use the event directly (in the case of a change event, it is event.target.files).

– The “fallback” to the file input button is a great idea. We decided to do something like this, but instead of “one or the other”, we always provide the input node. Only the drop area is optional and available on detection.

To streamline everything, we therefore only trigger the upload from a “change” event on the input node. The drop widget takes the files object and throws it over to the input node (document.getElementById(‘files-upload’).files = event.originalEvent.dataTransfer.files;), which triggers the change event.

Hope that’s some sort of benefit to someone!

]]>