Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
Upload Files to Web ServerDemonstrates how to upload files from an application to a web server. Note: There must be something provided on the server-side to consume the upload. It could be an ASP or ASP.NET script, Perl, C++ CGI, PHP, Ruby, etc,. However, uploading via HTTP is not the same as uploading via FTP where the FTP server handles receiving the file and saving to disk. The C# code behind http://www.chilkatsoft.com/receiveUpload.aspx may be found at this URL: C# to Receive Upload in ASP.NET. CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) DECLARE @success int DECLARE @http int EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- Any string unlocks the component for the 1st 30-days. EXEC sp_OAMethod @http, 'UnlockComponent', @success OUT, 'Anything for 30-day trial' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Build a HTTP request with the files to be uploaded: DECLARE @req int EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @req OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OAMethod @req, 'UseUpload', NULL -- The URL we'll be posting to is: -- http://www.chilkatsoft.com/receiveUpload.aspx -- Therefore, the path part of the URL is: EXEC sp_OASetProperty @req, 'Path', '/receiveUpload.aspx' -- Note: You may test uploads to this URL, but anything over 80K will be aborted on the receiving side. -- Add some files to the request: -- The 1st argument is an arbitrary name. It's the POST form field name. -- The 2nd argument is the filename currently existing on -- the local filesystem. It may include an absolute or relative -- path, or no path at all if it's in the current working directory. EXEC sp_OAMethod @req, 'AddFileForUpload', @success OUT, 'file1', 'hamlet.xml' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @req, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END EXEC sp_OAMethod @req, 'AddFileForUpload', @success OUT, 'file2', 'dude.gif' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @req, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Send the HTTP POST and get the response. Note: This is a blocking call. -- The method does not return until the full HTTP response is received. DECLARE @domain nvarchar(4000) DECLARE @port int DECLARE @ssl int SELECT @domain = 'www.chilkatsoft.com' SELECT @port = 80 SELECT @ssl = 0 DECLARE @resp int EXEC sp_OAMethod @http, 'SynchronousRequest', @resp OUT, @domain, @port, @ssl, @req IF @resp Is NULL BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 END ELSE BEGIN -- Display the HTML source of the page returned. EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT PRINT @sTmp0 END END GO |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.