Loading image from binary?

0 favourites
From the Asset Store
Progress\Loading Bar. Now Load you game like a Professional.
  • Set image from URL, set response binary, load array with binary code.

    Posted this to the server using AJAX (as a Blob), and cleared the storage, refreshed (everything is cleared out including local storage).

    Pulled the info back from the server and loaded into the array.

    My question, how does one load the stored binary code back into the a sprite?

  • Use the binary data's geturl expression with the sprite load from url action.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Some folks have gotten it to work by adding

    data:image/png;base64, in front of the base64 string and then loading via URL



    I've just not been able to get it working.

  • This works locally, and I'm still trying to figure out what a byte offset is and how the heck it works.

    The code below will not pass to the server without error (works fine on my local pc). Will update as I figure it out...day 2 is in the books lol. Hopefully a few more days (or less) I'll have something to report that works passing into mysql via phpmyadmin. I will say this, the base64 as a png file is to large.

  • Anyone have any ideas?

    I can upload base64 to the server up to around 5kb of data.

    Past that the upload fails.

    My guess is that it has to do with Apache limiting the URL to 8k characters.

    Is there way to compress this or use an alternative to base64? (if so could you point me in the direction of how to do that? I've read all of the forum comments and the manual. I was thinking I could take the base64 and apply float64(8) and unpack it. Unfortunately I couldn't figure out how to unpack it. At this point, I'm going to take a break...)

    As an aside, URLencode would not work either.

  • Ashley

    If we figure this out, I'm volunteering to do a tutorial.

    I've read every post (even one that was mistakenly put in C2 forum) and tried every combination I can conceive.

    Info being sent:

  • Use "Post binary to URL". Putting the entire base64 string in the URL will make the URL too big to request, and the binary URL is (IIRC) a blob: URL which refers to local content so cannot be accessed by a server.

    You could also post a base64 string, but that's wasteful compared to just sending the raw binary.

  • Ashley

    The buffer is 49k in length, so that's not looking at the url.

    The url is there, it's your blob preview option

    The float64(*) [personally I figured this should be 8, but 8 returns 0 so I used 1 and it returns what looks like the URL data in float64]

    Base64 reads and hold the actual file data, unfortunately the data amount is larger than the actual file.

    ***The only BinaryData.Get* that seems to return a value other than the URL is Base64.***

    (The best I can tell, base64 is also the only "Get" that can be stored in local storage and retrieved when the browser is close and reopened)

  • After 5 days, this is what I can say for sure.

    When sending the ajax request with a small data set, it works just fine.

    When the file is larger it gets this error:

    rkJggg==' from origin 'https://preview.construct.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

    This should be working...this is the only error I can not account for.

  • So the error I was getting is based on the server httpd file limitrequestline = 8190 and as such I'm unable to send the url of a picture in base64 that's larger than 8kb. Punt and look for a new method.

    (Just in case someone else has the issue. The way I figured this out was to copy the error url into the browser and it gave an error 414. But, at least one path has been thoroughly explored.)

  • Just to wrap this up.

    To send an image to the server using *.php via AJAX is doable.

    However, your server may limit the url to a certain number of characters (usually 8190 characters, this is to slow Denial Of Service (DOS) attacks against the server per Hostgator.) see 414 error*

    When retrieving data from the server, usually the url is unlimited (no need for them to worry about DOS when sending).

    The suggestion has been made to use a Blob, but the best I understand it, this is only done locally and is of no help when sending data over the internet.

    Using binary might reduce the url by 30%, but on a 5mb file, that is still well over the server threshold of characters and again makes the url too long to be sent.

    The only solution I see it to parse the data, send multiple AJAX post and just append the cell text that holds the picture data.

    Hope this information helps others.

    If anyone can add information to this, or sees an error please let me know. Thank you.

  • I previously suggested using "Post binary to URL", which sends the data in the body of the request, not the URL. Therefore it is not affected by URL length limits.

  • Well I learned something new today.

    I've used AJAX for 5 years (through C2) and never realized the URL line is a GET line only. Wasn't ever an issue before and never needed the POST. Now that I've figured that out, and CAN send, without issue, base64 to and from the server.

    This one is just out of curiosity and if you don't feel like responding no worries.

    What I do not understand:

    How does one specify where the binary data would end up (the specific cell inside the database_ using "Post binary to URL"?

    Binary to unspecified location (which is what I understand from your previous post).

    What I need to have happen, unfortunately this won't work, but hopefully you understand what I mean.

    (That is to say, there is no way to specify where the AJAX - POST binary to URL results should go.

    My normal way

  • Im looking for that answer also.

    I have to send the users id so the php can recognize who is sent the picture to store to his row but i dont know how to send the BinaraData.

  • How does one specify where the binary data would end up (the specific cell inside the database_ using "Post binary to URL"?

    The server will receive the data in the request body. It's up to your server code what it does with that.

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