New topic: 

Uploading files with HTTPSocket.Post

<http://forums.realsoftware.com/viewtopic.php?t=46612>

         Page 1 of 1
   [ 6 posts ]                 Previous topic | Next topic          Author  
Message        charonn0          Post subject: Uploading files with 
HTTPSocket.PostPosted: Fri Jan 18, 2013 6:30 pm                                 
Joined: Mon Apr 02, 2007 2:08 am
Posts: 1076
Location: San Francisco, CA, USA                I've been banging my head 
against this for some time, yet nothing I do seems to work.

I'm trying to use an HTTPSocket to upload a file to VirusTotal.com using their 
public API. The relevant part of their (skanty) documentation is here: 
https://www.virustotal.com/documentatio ... ning-files

My code:
Private Sub SubmitFile(File As FolderItem, APIkey As String)
  Const MIMEBoundary = "--------0xKhTmLMIMEBoundary"
  Dim CRLF As String = Encodings.ASCII.Chr(13) + Encodings.ASCII.Chr(10)
  Dim sock As New HTTPSocket
  
  dim stream as BinaryStream
  dim postContent as String
  postContent = postContent + "--" + MIMEBoundary + crlf
  postContent = postContent + "Content-Disposition: form-data; name=""file"""
  postContent = postContent + "; filename=""" + file.AbsolutePath + """"
  postContent = postContent + crlf + "Content-Type: application/binary" + crlf 
+ crlf
  stream = stream.Open(File)
  postContent = postContent + stream.Read( file.length )
  stream.close
  postContent = postContent + crlf
  postContent = postContent + "--" + MIMEBoundary + crlf
  postContent = postContent + "Content-Disposition: form-data; name=""apikey"""
  postContent = postContent + crlf + "Content-Type: text/plain" + crlf + crlf
  postContent = postContent + APIkey
  postContent = postContent + crlf
  postContent = postContent + "--" + MIMEBoundary + "--"
  
  sock.SetPostContent(postContent, "multipart/form-data, boundary=" + 
MIMEBoundary)
  Dim s As String = Sock.Post("www.virustotal.com/vtapi/v2/file/scan", 5)
  Break
End Sub


I get an HTTP 403 error. Any suggestions?      
_________________
Boredom Software  
                             Top                DaveS          Post subject: 
Re: Uploading files with HTTPSocket.PostPosted: Fri Jan 18, 2013 6:51 pm        
                         
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4441
Location: San Diego, CA                Quote:A web server may return a 403 
Forbidden HTTP status code in response to a request from a client for a web 
page or resource to indicate that the server refuses to allow the requested 
action. In other words, the server can be reached, but the server declined to 
allow the requested access.


So I'd say your creditials are incorrect      
_________________
Dave Sisemore
MacPro, OSX Lion 10.7.4 RB2012r1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top                charonn0          Post subject: 
Re: Uploading files with HTTPSocket.PostPosted: Fri Jan 18, 2013 7:02 pm        
                         
Joined: Mon Apr 02, 2007 2:08 am
Posts: 1076
Location: San Francisco, CA, USA                The API key is valid; all other 
API calls work, but no other API calls involve uploading a file.      
_________________
Boredom Software  
                             Top                J.Sh3ppard          Post 
subject: Re: Uploading files with HTTPSocket.PostPosted: Fri Jan 18, 2013 8:32 
pm                         
Joined: Tue Mar 23, 2010 8:44 pm
Posts: 541                Hi charonn0

I think Dave answered pretty well but I'll  shed more light on it.

I know 403 errors when the server's file permissions are set to NOT allow 
public access to the file(s) in question.


Assuming your code and their API directions are correct (I didn't check)  :

This is not something you as the client can correct. It requires server access 
to change permission settings which allow you the client access.


If your API code is not correct, then correct it 

You may want to get an HTTPsocket to upload  a file to your own server using 
php first to make sure your boundaries are correct, etc.


There might be a thread on this in the networking section.

I would offer more help but I'm totally swamped; Not only am I behind my own 
production schedule but I got suckered into making a website / online business 
for a family member for free 

Ps. I really want to WE to be working reliably !
Doing this stuff in php, CSS, HTML, etc. is boring and takes me a long time!!!!

Gotta look more at WE soon and put it to the test.   
                             Top                Bob Coleman          Post 
subject: Re: Uploading files with HTTPSocket.PostPosted: Sat Jan 19, 2013 6:08 
pm                         
Joined: Fri Nov 16, 2007 10:18 pm
Posts: 172
Location: Portland, OR                I notice that you are passing the 
absolute path in the filename parameter.  This is generally not allowed.  Try 
file.Name instead.      
_________________
Windows: Win7 64bit sp1, Vista 32bit sp2, WinXP 32bit SP3
Linux:  RH EL6
Mac: Died last year and took 2 months to notice.

RealStudio: 2012r2  
                             Top                charonn0          Post subject: 
Re: Uploading files with HTTPSocket.PostPosted: Sat Jan 19, 2013 6:13 pm        
                         
Joined: Mon Apr 02, 2007 2:08 am
Posts: 1076
Location: San Francisco, CA, USA                Good point, but by itself 
doesn't seem to help.      
_________________
Boredom Software  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 6 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

rbforumnotifier@monkeybreadsoftware.de

Reply via email to