How do I post file to server?

0 favourites
  • 3 posts
From the Asset Store
We present to you “Post Apocalyptic Trailer” – our newest hard hitting, bass rumbling designed movie trailer collection.
  • Hello,

    Looking for a starting point to send a file "image" to a folder in the server.

    I try with filechooser to send the fileUrl via Ajax and with canvassnapshot but the server receive an empty file.

    The canvassnapshot or the filechooser.fileUrl is the real file.png or im sending an empty file?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • savvito123

    I'm using php (transfer) and phpmyadmin (database), not sure what you're using.

    Using binary, filechooser, drawingcanvas, and ajax.

    filechooser to get the image and set a sprite from FileChooser.FileURLAt(0) (resize, etc)

    created drawingcanvas(dc) at the sprite x,y , drawingcanvas.paste, save as png

    On dc save set ajax response binary, then ajax request DrawingCanvas.SavedImageURL

    Once the ajax runs, set a variable to BinaryData.GetBase64. This variable can be used to pass the image.

    10mb phone pictures = 50kb base64 text, not tiny but much, much smaller and without much loss of quality.

    Later, when you need the image just pull the base64 string from server (using php) and load it into a sprite with BinaryData.GetBase64&ajax.lastdata

    If you want to save an actual file somewhere on the server, I'm not sure how to pass that in php but found a link.

    construct.net/en/forum/construct-2/how-do-i-18/save-json-file-server-119259

    (I ran into issues with passing this variable to the server because I didn't realize, in C3 an ajax "post to url", the URL line of ajax is a GET and the Data line is POST [meaning you have to adjust the $_GET and $_POST of the php file accordingly. Sending 50kb as a GET will be rejected by most servers (error 414 exceeds url length limit), but POST is allowed.)

  • Hello jsutton , thanks for your help.

    Im using php and phpmyadmin also.

    Its a long time im searching for a way to let the players upload an image mostly to use it to leaderboard.

    Yesterday i realised that its better to just send a file(picture) in a folder to the server with the uniqe id of the player and retreive it with the url/unigeid.png instead of overload the database with real pictures.

    Im make some test and i send a file to the server but its empty, i will try to send the binary.getbase64 to see the results.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)