How to upload a file from iPhone SDK to an ASP.NET vb.net web form using ASIFormDataRequest
Posted
by user289348
on Stack Overflow
See other posts from Stack Overflow
or by user289348
Published on 2010-03-14T16:13:59Z
Indexed on
2010/03/14
16:15 UTC
Read the original article
Hit count: 1466
Download http://allseeing-i.com/ASIHTTPRequest/. This works like a charm and is a good wrapper and handles things nicely. The make the request this way to the asp.net code listed below.
Create a asp.net webpage that has a file control.
IPHONE CODE:
NSURL *url = [NSURL URLWithString:@"http://YourWebSite/Upload.aspx"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
//These two must be added. ASP.NET Looks for them, if
//they are not there in the request, the file will not upload
[request setPostValue:@"" forKey:@"__VIEWSTATE"];
[request setPostValue:@"" forKey:@"__EVENTVALIDATION"];
[request setFile:@"PATH_TO_Local_File_on_Iphone/file/jpg" forKey:@"fu"];
[request startSynchronous];
This is the website code
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Upload.aspx.vb" Inherits="Upload" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="fu" runat="server" EnableViewState="False" />
</div>
<asp:Button ID="Submit" runat="server" Text="Submit" />
</form>
</body>
</html>
//Code behind page
Partial Class Upload
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim tMarker As New EventMarkers
If fu.HasFile = True Then
'fu.PostedFile
fu.SaveAs("E:\InetPub\UploadedImage\" & fu.FileName)
End If
End Sub
End Class
© Stack Overflow or respective owner