sending a file to a webpage (.gambas cgi)

Post

Posted
Rating:
#1 (In Topic #1266)
Banned
 How can i send a file to a webpage?

I want in my gambas application to be able to open a URL to a gambas cgi (gb.web) and post a file to it.

So on the computer side is a gambas program that wants to send file data.
And on the server end it receives the file data so it can then save it as a file.

The program and the online server are mine so I am free to do this another way if there is a better way.

It is for my Blockski+ program , I am making a Highscore repository/server so players can easily merge scoreboards.

I currently have it so i can HttpClient.Download() a .gambas cgi with various parameters so my program can simply download urls like

web.address/cgi-bin/Scores.gambas?getusers
web.address/cgi-bin/Scores.gambas?getscores=username

getusers just prints available users and getscores prints the users scores.
this is easy , the .gambas cgi just prints text so the result of the download it the text i want.

But how to reverse this so i can send a whole file.

I've tried httpClient.Post() but cannot get it to work.
I could do with an example of how to post data using httpClient.class

Cheers in advance for any tips
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Administrator
sholzy is in the usergroup ‘unknown’
 About 9 years ago I created an app to keep track of my parents doctors appointment. The app would also create an HTML file and upload that file to my server via FTP. I was then able to give the password protected URL link to siblings so they could also know the schedule. I don't remember if I uploaded to the exact location or if I moved it via a chron job. If I remember correctly, I tried to do it something like what you are trying but never was able to make it work so I went with the FTP route.

Maybe you can upload the file by FTP, and then move it to the proper location?

sholzy
Gambas One Site Director

To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Online now: No Back to the top

Post

Posted
Rating:
#3
Banned
 I can't use FTP as the program will be in the public domain.
So I Cannot really add my ftp login details to the app.

Needs to be sent by http push or post I think
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
I think, if I understand,  you need a public ftp directory on your server, i.e. one that the public can upload files to, and which should be very isolated from the rest of your server. This is possible, don't ask me, I threw my ftp manual out a decade ago.
Then you can write the stuff in your page to upload to that location via ftp. I think Gambas can handle that.
Now getting stuff out of there is a different kettle of fish.
(Caveat) It is about 10 or so years since I was doing that stuff.
hth
b

p.s. IIRC http is not for transferring files, just a bunch of text with a bunch of markup tags. Post is just the same and I've not heard of push but I'd guess ditto. ftp is OTOH for transferring files, maybe that's why they called it that.  :)

p.p.s. Maybe wade through the jcrap on a site like https://www.flaticon.com/ to see how they download files to the user pc,

p.p.p.s. <COLOR color="#BF40BF">I sit corrected</COLOR>. Maybe POST a File via HTTP Request | The Ultimate Guide | by API4AI | Medium could help

Online now: No Back to the top

Post

Posted
Rating:
#5
Banned
cheers Mr b
multipart/form-data looks promising

But what i don't know is how to process the request server-side

Here is what my program does to send the data

Code (gambas)

  1.  
  2. Public Sub btnUpload_Click()
  3.  
  4.   Dim sRes As String
  5.   Dim s As String = File.LoadArchive(File.SetExt(ESettings.Path, "zx"), True)
  6.  
  7.   With $hTp = New HttpClient As "HTP"
  8.     .URL = $sHost &/ $sScorePath & "submit"
  9.     .Post("multipart/form-data", s)
  10.  
  11.  
  12.  

the URL looks something like
127.0.0.1/cgi-bin/Scoreprog.gambas?submit

I can detect the "submit" in the QUERY_STRING server-side but then i do not know how to find the data sent? it does not seem to be in any CGI[Key] variable.
the client-side shows bytes are sent but how do i find the data server-side?

Cheers
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
gbWilly leads the usergroup ‘GambOS Contributor’
gbWilly is in the usergroup ‘Blogger’
 (Somewhat corrected post of my reply a second ago to this  question but on the gambas mailing list)

So what you are asking is, where is the file on the server or what?

I see: As server side can detect the submit, you know on server side that upload happened.
Now you want to go to the file from server side I presume, to do some stuff.
My guess is that the web server configuration determines the upload location and access rights to upload to there
And I guess your upload on client side determines the filename.

These are just some wild guesses that might set you on the right path (or not).

Haven' t used it myself, did use the opposite, downloading from server.

gbWilly

gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories


… there is always a Catch if things go wrong!
Online now: No Back to the top

Post

Posted
Rating:
#7
Banned
Seems i was missing Request.class and the Request.Post property

(who'd have thought that to process the request of posted data i had to use Request.Post  :roll:  )

The solution was the following….
Set
Request.Debug = True
send data with content type multipart/form-data

then server-side i can simply use

Code (gambas)

  1. Dim vData As Variant
  2. vData = Request.Post.Contents
  3.  

Easy as that :)

EDIT:
actually I found that way truncated data.

The following way worked much better and there is no need to set Request.Debug = True when doing it like this

Code (gambas)

  1. sTxt = Read Request.ContentLength
  2.  
Online now: No Back to the top
1 guest and 0 members have just viewed this.