Click here to Skip to main content
13,869,185 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I use this lines in my `aspx` code
<input type="file"  name="file1" id="file1" />;
  <input type="button" value="SendFile" onclick="uploadFile()"/>;<br />
  <progress id="progressBar" value="0" max="100" style="width:300px;"> </progress>
  <h3 id="status"></h3>
  <p id="loaded_n_total"></p>

And I also use this `script` in order to manage the Up Loading proses.
<script type="text/javascript">
function _(el){
	return document.getElementById(el);
}
function uploadFile(){
	var file = _("file1").files[0];
	// alert(file.name+" | "+file.size+" | "+file.type);
	var formdata = new FormData();
	formdata.append("file1", file);
	var ajax = new XMLHttpRequest();
	ajax.upload.addEventListener("progress", progressHandler, false);
	ajax.addEventListener("load", completeHandler, false);
	ajax.addEventListener("error", errorHandler, false);
	ajax.addEventListener("abort", abortHandler, false);
	ajax.open("POST","http://www.fileupload.ekkeross.com");
	ajax.send(formdata);
}
function progressHandler(event){
	_("loaded_n_total").innerHTML = "Uploaded "+event.loaded+" bytes of "+event.total;
	var percent = (event.loaded / event.total) * 100;
	_("progressBar").value = Math.round(percent);
	_("status").innerHTML = Math.round(percent)+"% uploaded... please wait";
}
function completeHandler(event){
	_("status").innerHTML = event.target.responseText;
	_("progressBar").value = 0;
}
function errorHandler(event){
	_("status").innerHTML =  "Upload Failed  " ;
}
function abortHandler(event){
	_("status").innerHTML = "Upload Aborted";
}
</script>


It works fine If I want to Up Load my current page.
But the image file that I select is not Up Load it.

Additionally I have to say this:

The current page is not saved in a directory but it comes up to the current browser page.
When I try to put any (legal) directory in
ajax.open("POST","http://www.fileupload.ekkeross.com");

like
ajax.open("POST","http://www.fileupload.ekkeross.com/App_Data/FileUpload");
returns an error. which says:
"Directory Not Found"

I haven't mention for my upload file... that is nowhere.
The `script` I found it in Here

Please assist me on this


What I have tried:

Nothing except the







above
Posted
Updated 11-Jan-19 3:47am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

That code doesn't save the image to the target url, it POSTs the image to a page with the expectation that that page is a file upload page that reads the file from the form data and saves it somewhere on the target website. As for the app_data folder that is not publicly accessible for security reasons, but as mentioned above you won't need to POST to it anyway.

The url below has an example of the kind of code that needs to exist on the page you POST to

Uploading Files in ASP.NET 2.0 | Microsoft Docs[^]

If you want the client to dictate where about the file is saved then you'd need that data in one of the form variables so that the target page knows where to SaveAs, but be aware of the security concerns of doing that, a malicious person could supply any oath they want and could overwrite the files on your server.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190214.1 | Last Updated 11 Jan 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100