posting binary data to thirdparty site

This is a discussion on "posting binary data to thirdparty site" within the Classic ASP section. This forum, and the thread "posting binary data to thirdparty site are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Closed Thread
 
LinkBack Thread Tools
  #1  
Old Aug 18th, 2003, 00:02
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
( ) isn't the correct delimiter for a string, you need to using single quotes, so this:

<blockquote id="quote"><font size="1" face="geneva, verdana, arial" id="quote">quote:<hr height="1" noshade id="quote">newSQL = "Update Business SET Background=("&Image&") Where ID=" & tkey
<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">

should be:

newSQL = "Update Business SET Background='"&Image&"' Where ID=" & tkey

- Cat
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Aug 9th, 2004, 14:53
Junior Member
Join Date: Sep 2003
Location: Vatican City
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
posting binary data to thirdparty site

Hi, we are developing a site. One part of it requires us to send image files to a thirdparty's URL.

This isn't image upload problem... we can do that, the question concerns sending this binary data to another url which we don't control.

We normally use the ASP xml components to GET data from another site, however in this instance we have to post BINARY data to another site, which it appears the xml components don't support.

Any ideas how to do this. Yes I know its easier to ftp or mail the images... but this is a thirdparty site, we can't rewrite their ****ty API for them!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old Aug 9th, 2004, 17:35
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
You might check out SOAP, it can send binary data using ASP.

http://www.google.com/search?hl=en&l...end+binary+asp

I guess it depends on what they've got setup for receiving the data on the other end though.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #4  
Old Aug 9th, 2004, 18:52
Rob's Avatar
Rob Rob is online now
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,154
Blog Entries: 7
Thanks: 26
Thanked 19 Times in 16 Posts
it's a standard html form Cat....
I think I've cracked this... will keep posted.
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #5  
Old Aug 10th, 2004, 14:57
Rob's Avatar
Rob Rob is online now
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,154
Blog Entries: 7
Thanks: 26
Thanked 19 Times in 16 Posts
Ok.... Me and nick cracked this.
I'll put an article together at a later date to show uses for this script.
Essentially, it allows posting form fields, and files to multi-part/form-data form handlers without user interaction.

Here's the code:-
Code: Select all
<%
'#################################################################################
'## Created in 2004  Robert Collyer  (WWW.WEBFORUMZ.COM)
'##                      and Nick Jones  (WWW.CACTUSOFT.COM)
'##
'## This notice
'## must remain intact in the scripts
'##
'## This code is distributed in the hope that it will be useful,
'## but WITHOUT ANY WARRANTY; without even the implied warranty of
'## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
'##
'## Portions of this code are based upon work carried out by Antonin Foller, PSTRUH Software
'## and credits are duly given to him for his work.
'##
'## Support can be obtained from the ASP support forums at:
'## http://www.webforumz.com
'#################################################################################

Class MultiPartFormPost
	Public Boundary 
	Private NewData 
	Private PreviousData 
	Private ItemString 
	Private blnLastItem
	
	'The next two functions build up a string of form elements and files to add
	'to the form post.
	Public Sub AddFile(LocalPath,FieldName)
		ItemString = ItemString & "FILE^^" & LocalPath & "^^" & FieldName & "||"
	End Sub
	
	Public Sub AddField(FieldName,FieldValue)
		ItemString = ItemString & "FIELD^^" & FieldName & "^^" & FieldValue & "||"
	End Sub
		
	Public Function Send(URL)
		If Boundary = "" then Boundary = "webforumz.com-MultipartFormPost" 'Default Boundary
		'Remove the last divider element
		ItemString = left(itemstring,len(itemstring) - 2)
		'Create an array of the various form elements to post
		Items = Split(ItemString,"||")
		For count = 0 to ubound(Items)
			'Preserve the Current Binary Data
			PreviousData = NewData
			'Grab the data needed to post each form element 
			ItemPart = Split(Items(Count),"^^")
			'Are we dealing with the last element?
			If count = UBound(Items) Then blnLastItem = True
			If ItemPart(0) = "FILE" Then 
				AddItem 0,ItemPart(1),ItemPart(2) 'Add File
			else 
				AddItem 1,ItemPart(1),ItemPart(2) 'Add Field
			end if
		Next	
		'Create HTTP object to Post the data
		Set http = CreateObject("MSXML2.ServerXMLHTTP")
		http.Open "POST", URL, False
		http.setRequestHeader "Content-Type", "multipart/form-data; boundary=" + Boundary
		'Send the Data, and grab the response.
		http.send NewData : Send = http.responseText : set http = Nothing
	End Function	
	
	Private Sub AddItem(FType,arg1, arg2)
		If FType = 1 then 'Add field
			NewData = BuildFormData(arg1, arg2,"")
		else 'Add file
			Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
			'Does the file exist?
			if Not objFSO.FileExists(arg1) then Exit Sub
			'Grab the file data as binary.
			Set Stream = CreateObject("ADODB.Stream")
			Stream.Type = 1 : Stream.Open : Stream.LoadFromFile arg1
			FileContents = stream.read
			'Build this elements RAW HTTP Data
			NewData = BuildFormData(FileContents, arg1, arg2)
			'Clear up!
			stream.close : set stream = nothing : Set FSO = Nothing
		end if
	End Sub
	
	Private Function BuildFormData(arg1, arg2, arg3)
		'Have any items been added yet?
		If lenb(PreviousData) > 0 then 
			pre = vbCrLf 
		else 
			pre = "" 
		end if
		
		'Arg3 will be blank if dealing with a Field Element
		If arg3 <> "" then 'File Element
			'Set the Element's preceding HTTP String
			Pre = Pre & Boundary & vbCrLf & "Content-Disposition: form-data; " & _
			"name=""" & arg3 & """; filename=""" & arg2 & """" & vbCrLf & _
			"Content-Type: application/upload" & vbCrLf & vbCrLf
		else 'Field Element
			'Set the Element's preceding HTTP String
			Pre = Pre & Boundary & vbCrLf & "Content-Disposition: form-data; " & _
			"name=""" & arg1 & """" & vbcrlf & vbcrlf
		end if
		'Are we dealing with the last element?
		If blnLastItem then
			'Set the last element's finishing HTTP String
			Po = vbcrlf & Boundary + "--" + vbCrLf 
		else 
			Po = "" 
		end if
		'Create a  recordset instance so we can manipulate binary data
		Set RS = CreateObject("ADODB.Recordset") 
		If arg3 <> "" then 'File Element
			RS.Fields.Append "b", 205, Len(Pre) + LenB(arg1) + Len(Po)
		else 'Field Element
			RS.Fields.Append "b", 205, Len(Pre) + Len(arg2) + Len(Po)
		end if
		RS.Open : RS.AddNew 'Create a record within the recordset object
		LenData = Len(Pre)
		'Convert the preceeding HTTP String to binary
		RS("b").AppendChunk (StringToMB(Pre) & ChrB(0))
		Pre = RS("b").GetChunk(LenData) : RS("b") = ""
		If blnLastItem then ' Last element?
			'Convert the last element's finishing HTTP String to binary
			LenData = Len(Po) : RS("b").AppendChunk (StringToMB(Po) & ChrB(0))
			Po = RS("b").GetChunk(LenData) : RS("b") = ""
		end if
        if arg3 = "" then 'Convert Field's Value to binary.
			LenData = Len(arg2) : RS("b").AppendChunk (StringToMB(arg2) & ChrB(0))
			arg2 = RS("b").GetChunk(LenData) : RS("b") = ""
		end if
		'If there was already Binary Data (form elements), then we add this in front
		'of this element's binary data
		If LenB(PreviousData) > 0 then RS("b").AppendChunk (PreviousData)
		'Add the preceding HTTP String Binary
		RS("b").AppendChunk (Pre)
		if arg3 <> "" then 'Add the Binary File Data
			RS("b").AppendChunk (Arg1) 
		else 'Add the Binary Field Value
			RS("b").AppendChunk (arg2)
		end if
		'If we are on the last element, add the finishing binary data
		If blnLastItem then RS("b").AppendChunk (Po)
		'Return the Binary to calling function
		RS.Update : FormData = RS("b") : BuildFormData = FormData
		'Clear up.
		RS.Close : Set RS = Nothing
	End Function
	
	Private Function StringToMB(S)
		'This function converts a string, to a binary string
		B = ""
		For I = 1 To Len(S)
			B = B & ChrB(Asc(Mid(S, I, 1)))
		Next
		StringToMB = B
	End Function
End Class%>
Example Usage:
Code: Select all
<%
Set frmPost = New MultiPartFormPost
'Add a file (as if you clicked the browse button on a form)
frmPost.AddFile Server.MapPath("/images/myimage.jpg","FileInputFieldName")
'Add a Form Field
frmPost.AddField ("FieldName","FieldValue")
'you can call the above steps as many times as nessesary
'next, we send the output to the form
frmPost.Send("http://www.myurl.com/myFormHandler.asp")
Set frmPost = Nothing
%>
Feel free to use the above, keeping notice at head of code intact.

Hope this helps!
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Tags
posting, binary, data, thirdparty, site

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
trouble posting videos to my site barkpark Flash & Multimedia Forum 3 Jan 23rd, 2008 19:36
binary data(image) loading and display in asp aparna2402 Classic ASP 1 May 17th, 2006 12:26
[SOLVED] Presenting binary values Anonymous User Classic ASP 3 Dec 7th, 2004 17:50
Send Binary Data vor Classic ASP 1 Aug 21st, 2003 14:38


All times are GMT. The time now is 15:08.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42