Code Monkey home page Code Monkey logo

Comments (7)

agentphantom avatar agentphantom commented on May 22, 2024

Thank you for sharing this!

I actually tried to use Firebase database in a Flash Player project but for some reason I wasn't able to connect to it. That's why I ditched the idea of using Firebase on Flash Player altogether.

Since Firebase Storage is actually Google Cloud Storage it might be the reason that one works well on the Flash Player.

from firebase-as3.

veselekov avatar veselekov commented on May 22, 2024

@agentphantom I haven't tried using it through the web. But I was able to get an upooad happening through flash player on desktop. Might require some crossdomain exceptions

from firebase-as3.

veselekov avatar veselekov commented on May 22, 2024

More progress on the Flash Player based code. You will need to use a phpProxy such as the one attached and affix the upload URL on your website to your Firebase url request. I've tested this with getting data from realtime database but I am still yet to be able to send.

So when you go to do a URLRequest with your firebase url do this

var phpProxy:String = "http://www.example.com/phpProxy.php?url=" //this has to be on the same website your swf is uploaded to
var appID:String = "" // YOUR APPLICATION ID

var request:URLRequest = new URLRequest(phpProxy+"https://"+appID+".firebaseio.com")
var loader: URLLoader = new URLLoader();
var rawData: Object;
loader.addEventListener(Event.COMPLETE, newsLoaded);
loader.load(request);

function newsLoaded(event:Event){
	rawData = JSON.parse(event.currentTarget.data);
	//rawData is your DB info. To access a node called 'World' just use rawData.World
}

phpProxy.php.zip

from firebase-as3.

agentphantom avatar agentphantom commented on May 22, 2024

Very interesting. I remember doing something similar like this in the Twitter 1.0 API days.

I have been working on something similar. A port of this guide but for Python which can be used as a proxy.

https://github.com/agentphantom/firebase-python

from firebase-as3.

veselekov avatar veselekov commented on May 22, 2024

@agentphantom
I am finding that the php works for images other than the ones used on firebase storage. Perhaps it is to do with the download tokens.

from firebase-as3.

veselekov avatar veselekov commented on May 22, 2024

@agentphantom So I bit of an update. The php proxy which I've attached earlier can read data from the web. But when it goes to 'PATCH' data it returns what is already there rather than updating it. I am looking into this however if you've got any suggestions seeing as you've worked through a php proxy before let me know.

Here is the php proxy at the moment:

<?php

$post_data = $HTTP_RAW_POST_DATA;

$header[] = "Content-type: text/xml";
$header[] = "Content-length: ".strlen($post_data);

$ch = curl_init( $_GET['url'] ); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

if ( strlen($post_data)>0 ){
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}

$response = curl_exec($ch);     
$response_headers = curl_getinfo($ch);     

if (curl_errno($ch)) {
    print curl_error($ch);
} else {
    curl_close($ch);
    header( 'Content-type: ' . $response_headers['content-type']);
    print $response;
}


?>

I am wondering what would be needed so that the Header will 'PATCH' data rather than just returning it.

from firebase-as3.

veselekov avatar veselekov commented on May 22, 2024

@agentphantom Got it working! So this has gotten a bit derailed from the original upload in flashplayer topic. But here is where I found luck at patching to Firebase
So all you need is a couple of tweaks to the php and the URLRequest. Here is all you need to change.

First the PHP

<?php

$post_data = $_POST['data'];

$ch = curl_init( $_GET['url'] ); 
$header = array( "X-HTTP-Method-Override: PATCH");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

if ( strlen($post_data)>0 ){
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}

$response = curl_exec($ch);     
$response_headers = curl_getinfo($ch);     

if (curl_errno($ch)) {
    print curl_error($ch);
} else {
    curl_close($ch);
    header( 'Content-type: ' . $response_headers['content-type']);
    print $response;
}


?> 

Now for all you need to change in the URLRequest from the post earlier. All you need to do is send the data as a a URLVariable so the php can interpret it as $_POST['data']

var proxyURL:String = [URL TO PROXY ABOVE]
var directory:String = [TARGET-DIRECTORY]
var request: URLRequest = new URLRequest(proxyURL+directory + "/.json");
var urlVars:URLVariables = new URLVariables();
urlVars.data = JSON.stringify(myObject); // create this
//request.data = JSON.stringify(myObject); // Instead of sending this
request.method = URLRequestMethod.POST;
request.requestHeaders.push(header);
request.data = urlVars // so you can send this

I am going to test with Firebase storage now. But that is one way of doing it.

from firebase-as3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.