Upload a File in ASP.net MVC2 using C# - asp.net-mvc-2

I have seen a great many tutorials about how to do file uploads. So far none of them really line up at all with what I am trying to do. Which is using the MVC method to, without using anything third party, upload an image to the web server and verify the size of the image. Almost all of the tutorials I have seen show how to do an upload in web forms. If anyone could point me to a tutorial that is MVC based or produce a short example that would be fantastic.

Did you try to use controller method with HttpPostedFileBase parameter?
Like
<form>
<input type="file" name="fileUploader" />
<input type="submit" />
...
and
public ActionResult AcceptFile(HttpPostedFileBase fileUploader)
{
....
}

Related

Shopify form post to external url

I have a site hosted with Shopify. I would like to implement a form that posts to an external url. This is a custom form. My original thought is that I could just create a new page and add a form similar to these examples here - http://wiki.shopify.com/Contact_And_Signup_Forms#Signup_Forms
But, I don't see an option to post to an external url. I am completely new to Shopify. I had hoped that being a rails programmer would have helped, but it looks like I need to work with the liquid template system and not rails.
Any assistance would be appreciated.
Instead of using the liquid form tag, just use straight HTML and specify an action for your form that points to an external URL.
Example:
<form action="http://your-url.com" method="post">
<input type="text" name="email_address">
<input type="submit" value="Go!">
</form>
The above example will POST to http://your-url.com.

RESTful way of File Uploading

I want to implement file upload in RESTful way using openrasta but not able to find proper way to implement it.There are few ways like using Ajax file upload or using Iframe which i could find.
Can anybody suggest any way of doing this or provide me some resources from where i can refer.
Thanks in advance
It seems to me you're trying to build file uploading in an html environment.
You have two choices.
Use an HTML form to upload the file.
<form enctype="multipart/form-data" action="/files" method="post">
<fieldset>
<input type="file" name="filename" />
<input type="submit" />
</fieldset>
</form>
You can map that in OR very easily. Your handler would look like this:
public object Post(IFile filename) { /* do something with the file */ }
You can't do ajax-based file upload with progress bars as there is no way in pure xmlhttprequest to manipulate binary files. If you go down the route of using a flash / silverlight control behind the scene, you'll just need to make sure you post the content of the file to /files as in the previous example, the easiest way being to send the content with a Content-Type http header of application/octet-stram, and the same handler code will just work.

Simple ASP Textbox Call

i am a front-end coder, so i don't know much about ASP
one of my clients called me for a simple help and i didn't refuse him.
What he wants is a simple text box with a submit button, and when he submits a text, lets say "Sample", he wants the server to call http://example.com/Sample.pdf after submission.
Simply, that is what i have at the moment:
<form action="form_action.asp">
<input type="text" name="pdf" value="enter pdf id" />
<input type="submit" value="Submit" />
</form>
It would be better if i can get a working answer as i don't have asp server on my computer, i will not be able to test it.
Any help will be appreciated. Thanks.
This is a very bad idea, especially when the implementer doesn't have an understanding of back-end coding. You are opening up the server to a whole heap of security issues.
If you allow anything to be put in this box, what would stop me entering ../includes/dbsettings.asp for example and getting access to files I really shouldn't have access to?
How will you handle if the file doesn't exist?
Actual Answer: This is a Q&A site, so here is the answer you requested, be careful what you do with it!
The following in it's own ASP page should do what you want:
<%
Response.Redirect("/" & Request.Form("pdf") & ".pdf")
%>
You can (and should) get more complex by setting mime type, designating it as an attachment (so a download box is spawned), streaming the file and above all adding security and error checking.

Submit a file element with jquery and ajax: No plugins wanted!

I'm trying to do a submit via ajax of a form that contains a file element.
<form id="classic_upload" enctype="multipart/form-data>
<input type="file" name="file" id="file"/>
<br/>
<!-- ...other inputs...-->
<button type="button" id="classic_save"> Send </button>
</form>
What I need to do is to submit this form and check if the file fulfills some requirements, so I wrote an ajax submit for this form
$('#classic_save').click(function(){
$.ajax({
type:"POST",
url:'<g:createLink action="classicUploadFile" controller="scan"/>',
success: function(msg){
alert("Data Loaded: " + msg);
}
});
});
However, I have no idea how to send the file through ajax.
Some context
Originally we were using swfUpload for this. However, we ran into some trouble with https and some certificate issues. So we decided to implement a basic html fallback. Plugins are nice, but we need to guarantee that this fall back is bullet proof (thinking of google mail "classic upload").
Any thoughts? Are iframes the way to go (read somewhere google mail uses them for their classic upload)
Thanks in advance.
If you like, there is jQuery Uploadify plugin to do exactly what you are looking for other than other great features.
I use the jQuery AJAX form plugin on my site to upload files.
Here you'll find a really good example/tutorial how to upload one file http://www.phpletter.com/Demo/AjaxFileUpload-Demo/
Hope it works for you.
Cheers

jQuery form processing

Does anybody know of a simple jQuery form processing tutorial that actually works?
I have a form I want to process via jQuery/Ajax nothing difficult in PHP but in jQuery and AJAX can I get it to work - no, all the tutorials are based round sending e-mails (or just lists of more lists of more lists of tutorials - hate those)
All I want to do is learn how to send a form via jQuery and AJAX to another page, save the data in a DB without having to leave the first page. I have tried all sorts but nothing works properly. Here is my form:
<form id="form">
<input type="text" name="abc" />
<input type="text" name="def"/>
<input type="text" name="ghi"/>
<input type="submit" name="try" id="try" />
</form>
Now what do I actually do? Sounds silly I know (and I guess I'll get another -1 star for this question) but I will be honest a GOOD simple tutorial would be really useful not just to me but to the others. I know php but jQuery/Ajax - just don't know/understand. I will not be alone
This is one of the good tutorials on how to submit forms using ajax and php.
This link is a reference teaching how to submit forms via jQuery/AJAX. Have the form post to a PHP page to handle the form data.
In short, your jQuery code would look similar to this:
$("#form").submit( function()
{
// Handle validation or any extra data here.
// Return true if validation passed and the data should be posted
// Return false if the form should not be submitted
// You can also do any extra work here that you like before returning,
// including changing something on the page or showing the user a message.
}
There's a cracking plugin for this:
http://plugins.jquery.com/project/form/
It's as easy as:
$('#myForm').ajaxForm(function() {
alert("Thank you for your comment!");
});