Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Sending an file to the server [HTTP] - Need an example

Author
Message
kamac
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 2nd Jun 2012 14:07
Hey.

Could somebody probably give me an working example of sending an file by usin HTTP commands?

I cannot get this to work...

Follow me on twitter! @MotionStruct
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 3rd Jun 2012 01:43
What language are you using at server side ? asp ? php ? jsp ? other ?
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 3rd Jun 2012 02:42
Also, do you have universal write permission on the directory you are trying to write to?

An example of the code that has not been working for you might help us to figure out what needs to be done.

Cheers,
Ancient Lady
kamac
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 3rd Jun 2012 11:38
Quote: "What language are you using at server side ? asp ? php ? jsp ? other ?"


I would like to see an example for anything but PHP. For me, in general, PHP's syntax sucks. If it would be possible with JavaScript, then I'd be glad to look at such script. If not, then ASP is next.

Quote: "Also, do you have universal write permission on the directory you are trying to write to?"


Well, I have access to server's FTP.

Quote: "An example of the code that has not been working for you might help us to figure out what needs to be done."


Not really, because I need an example of uploading a file to the server. Then the server stores it somewhere.
I guess that on client's side it's only:




Which I would like to upload file.txt onto the server as tests/some.txt.

Follow me on twitter! @MotionStruct
MarcoBruti
13
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 3rd Jun 2012 18:10
sorry, I do not think that you can upload a file only using a client-side script. JavaScript is client-side, not server-side.
This is true both if you use AJAX techniques or standard POST HTTP requests. So you will have to learn some clumsy syntax as PHP, Python, Ruby, or, if we want really have fun, PERL.
PHP is not so bad, it is C-like...
Here a link about the issue:
http://www.sitepoint.com/html5-ajax-file-upload/
kamac
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 3rd Jun 2012 18:44
The tutorial you gave Marco is about uploading files to the server, but on browser only.

I have no idea how to connect AGK's SendHTTPFile with PHP to save it.

Follow me on twitter! @MotionStruct
Pilz X Schizo
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Massachusetts, USA
Posted: 3rd Jun 2012 19:19
Kamac, you may find this useful,

http://w3schools.com/php/php_file_upload.asp

w3schools is a great resource for web development, I think that page will help you with your file upload.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 3rd Jun 2012 19:20
Quote: "Well, I have access to server's FTP."


As long as the connection is using the same username/password that you use for your ftp connection, you should be able to upload to the directory you first see when you make the connection.

I'm assuming that the connection made by AppGameKit will handle the username properly. If the site you are aiming at is Linux based, directory permissions are tightly handled.

If the 'tests' directory exists already, you should check the write permissions on it with whatever ftp tool you use.

If it doesn't exist, you need to create it and make sure that the write permission for owner is set and that it is owned by the username you will be connecting with.

The documentation for the SendHTTPFile command are not very clear, and a bit confusing. I would think the description for 'szServerFile' is incorrect, since it talks about the file being requested. The description also talks about the file being requested. I think someone fumble-fingered that particular help page.

I would expect that the 'szServerFile' parameter is supposed to be the name/location of the file after it has been received.

I also expect that you should not need to do anything server side for this command, since you are sending, not receiving. So, there should be no need for an example of what is on the server (PHP, asp, or whatever).

Cheers,
Ancient Lady
Pilz X Schizo
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Massachusetts, USA
Posted: 3rd Jun 2012 21:38
Kamac, I have messing around with this for a bit and got everything working from a simple HTML form. When I run it with the SendHTTPFile I get the response back from the script, but it is empty, Seems like something needs to be set with the post data. No idea what needs to be passed to make it work. My guess is a name variable to make the file commands on the PHP side work.

This is interesting, so going to continue to mess around with this and see what I can find out.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 3rd Jun 2012 22:21
Pilz, did the file you attempted to upload make it where you intended it to go?

Cheers,
Ancient Lady
Pilz X Schizo
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Massachusetts, USA
Posted: 3rd Jun 2012 23:01
@Ancient Lady: With the HTML form / PHP Script it works perfect and the file goes exactly where I want.

HTML Form:


PHP Upload Script:


This is my AppGameKit Code (Tier 2, but can be converted easilly)



I get the status of the file upload (Percentage complete) then it gives me the PHP response, all fields are empty though and there is no file on my server in the uploads folder.

My best guess is passing the proper Post data to make it work. I have tried every combination of name=file&id=file&type=file for the post data. just does not seem get what it wants.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 3rd Jun 2012 23:52 Edited at: 3rd Jun 2012 23:52
Quote: "With the HTML form / PHP Script it works perfect and the file goes exactly where I want."


Do you mean when you run them from a web browser (not in the app)?

If not, and they show up where you want, then it works.

While you are setting the text to indicate done when GetHTTPFileComplete shows complete (and sending), you should set your second string there.

I see two problems with your code here (one may be my understanding of something:


The first is that I don't think GetHTTPResponseReady is the correct one to call. It is meant for when you use the SendHTTPRequestASync command.

The other is "agk::SetTextString(2, agk::GetHTTPResponseC(HTTP))". This looks like a typo, 'GetHTTPResponseC' is not a command, but 'GetHTTPResponse' is.

Try this:


I will say that I haven't tried any of this, yet. I am going on what the documentation says and my own understanding of how code works.

Cheers,
Ancient Lady
Pilz X Schizo
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Massachusetts, USA
Posted: 4th Jun 2012 00:09 Edited at: 4th Jun 2012 00:43
Yes, from a browser it works fine.

The GetHTTPResponseC is a Tier 2 command, makes it so you don't have to clean up the string afterwards. (good eyes though )

I think the send file command is an Async request. which is why GetHTTPResponseReady was used to get the response. It is what the documentation says anyways, but that could be wrong.


As for what the problem is, I think it is what the input field name should be. In HTML the input field name is being passed to the script, from AppGameKit we have no way of telling it what the name is, my assumption is we need some more info on how the command is actually sending the file.



EDIT: Got it working from AppGameKit, the input field name that AppGameKit is using in the SendHTTPFile command is 'myfile' so the PHP Script should be this...



in your program just send to that php file and it will put your uploaded file in the uploads folder. that was fun.

EDIT 2: also all the ehco commands in the PHP file do not need to be there unless you want to check the response from the server. The only command that is really needed in that entire script is the move_uploaded_file.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Jun 2012 00:42
Ok, understood.

How about, just for yuts and giggles, trying my code snippet, substituting GetHTTPResponseC where appropriate. I'd be curious to see if it made a difference.

We need someone from TGC to weigh in on this. I still think it should be just a matter of passing the location for the file to go in and the location for the file you are sending. Anything else really requires that they provide us a good example of how it's supposed to work. The documentation really doesn't cut it for this process.

I'd like to know how it is supposed to work.

I know from my experience doing Ajax bits that trying to create the file upload object for a submitted 'page' is very difficult. I don't see a simple way to put it in standard args. There is a bunch of structure, as you can see in your PHP example, that needs to be handled.

Cheers,
Ancient Lady
Pilz X Schizo
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Massachusetts, USA
Posted: 4th Jun 2012 00:45
@Ancient Lady: Edited my above post, original program works great. was the PHP side of things not having the input field name.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Jun 2012 00:49
Cool! I'm glad you got it working.

If you could post the entire set of files (without actual domain, username, password, of course), this would be an incredibly helpful post for other people.

Happy Programming!

Cheers,
Ancient Lady
Pilz X Schizo
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Massachusetts, USA
Posted: 4th Jun 2012 01:18 Edited at: 4th Jun 2012 05:16
Be sure to have a folder called uploads in your root folder of your web server. In Tier 1 file.txt should be in your media folder. In Tier 2 your file.txt should be in your Final folder (or where your .exe is generated to)


file_upload.php



Tier 1: HTTP Send File



Tier 2: HTTP Send File



Hope this helps everyone out, and I hope TGC updates the Documentation a little, be good to know that the Input Field name is myfile.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Jun 2012 01:30
Pilz, you rock!

Is your handle in any relation to a style of beer?

Kamac, this should be what you need.

Happy Programming!

Cheers,
Ancient Lady
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 4th Jun 2012 02:03 Edited at: 4th Jun 2012 02:04
Pilz, you have forgotten to remove an "agk::" in your Tier1 example
Pilz X Schizo
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Massachusetts, USA
Posted: 4th Jun 2012 05:23
MikeMax: oops, ...fixed now. Tested befor I posted, worked on that computer for some reason. Thank you for pointing that out.

Ancient Lady: That is possible, although it would be more fitting if it were Lager
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Jun 2012 06:20
Good to hear.

My husband brews a great lager, and a very nice hoppy ale, and a great chocolate stout (serious desert quality).

Personally, I'm not a fan of whit beers or pilsner styles.

Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-11-23 14:47:57
Your offset time is: 2024-11-23 14:47:57