Kodewerx

Our culture has advanced beyond all that you could possibly comprehend with one hundred percent of your brain.
It is currently Thu Dec 05, 2024 8:54 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Dropbox Servers
PostPosted: Thu Feb 03, 2011 1:49 am 
Offline
Komrade
Komrade

Joined: Tue Mar 27, 2007 10:18 am
Posts: 1328
I've been wanting to use my Dropbox account to host a website on the Dropbox servers. It'd be super convenient!

Unfortunately the Dropbox servers do no parsing of pages when returning them so I am limited to working with HTML, CSS and JS.

How could I possibly manage a database with just that?! What sort of interesting things can I even do with this free hosting I have?

I do have administrative access to a web server that actually does process PHP but it is kind of unreliable and I don't want to reuse the domain if I don't have to.

Of course, I'm not even making a website but rather am just curious what I can do.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Dropbox Servers
PostPosted: Thu Feb 03, 2011 9:19 pm 
Offline
Krew (Admin)
Krew (Admin)
User avatar

Joined: Sun Oct 01, 2006 9:46 pm
Posts: 2331
Location: *poof*
Title: The Mad Hacker
Does dropbox server html as a normal webpage instead of a file download..?

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Dropbox Servers
PostPosted: Fri Feb 04, 2011 1:32 am 
Offline
Krew (Admin)
Krew (Admin)
User avatar

Joined: Sun Oct 01, 2006 9:26 pm
Posts: 3768
Title: All in a day's work.
Check out Tiddlywiki. It's a wiki that runs entirely on the client side. eg. JavaScript.

See? There are very good things you can do without dynamic server-side scripting.

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
 Post subject: Re: Dropbox Servers
PostPosted: Sun Feb 06, 2011 4:36 am 
Offline
Komrade
Komrade

Joined: Tue Mar 27, 2007 10:18 am
Posts: 1328
James - It just serves the content directly. So yes, HTML will be rendered in the browser instead of offered for download.

Jason - That's pretty sweet!...but what about persistence?

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Dropbox Servers
PostPosted: Sun Feb 06, 2011 1:28 pm 
Offline
Krew (Admin)
Krew (Admin)
User avatar

Joined: Sun Oct 01, 2006 9:26 pm
Posts: 3768
Title: All in a day's work.
You mean, it doesn't use any kind of HTML5 client-side database? Well that's a shame. If you want to make persistent changes on the server, you might want to look into what kind of REST APIs are available for DropBox (if any) and then a little JS magic can make it happen.

Edit: This.

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
 Post subject: Re: Dropbox Servers
PostPosted: Mon Feb 07, 2011 11:46 pm 
Offline
Komrade
Komrade

Joined: Tue Mar 27, 2007 10:18 am
Posts: 1328
I don't know what it's using, but I meant persistence that could actually be served between users.

I've having trouble wrapping my head around how this works. I get that I could use the API to store things on my Dropbox which could then be served, but the application implementing the API would be where? I'd want it in the public folder of my Dropbox, but then it would need to be an HTML file with JS embedded, and then the JS would need a way to tell something less public what to do...what could it talk to if there's no script execution on the server? Does Dropbox's API communicate with something like what I need that I am not aware of the existence of? Is this going to be secure? Am I even asking the right questions?

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Dropbox Servers
PostPosted: Tue Feb 08, 2011 1:50 am 
Offline
Krew (Admin)
Krew (Admin)
User avatar

Joined: Sun Oct 01, 2006 9:26 pm
Posts: 3768
Title: All in a day's work.
The Dropbox REST API allows applications to read/write data on the server using standard HTTP methods, I believe POST is used for writes. That means any of your standard "AJAX" calls can make that happen. In JavaScript, that's usually done with XMLHttpRequest or jQuery's $.ajax. I suggest the jQuery method, since it's a piece of cake:

Code:
$.ajax("https://api.dropbox.com/0/[email protected]&password=MyPassword)

Of course, since you brought up 'security' ... you can see right there your email address and password will be in the cleartext JavaScript, and could be fished out of it easily. A more secure method is to ask the user for authentication credentials:

Code:
$.post("https://api.dropbox.com/0/token", {
    email: encodeURI(email),
    password: encodeURI(password)
})

This one uses $.post, just to show another way of making the REST call. It does not increase security, since both methods are encrypted with HTTPS.

All you really need now is a callback to receive the response to verify that authentication was successful, and the token/secret from that response can be used for further requests, like using the files call to upload a file.

Code:
var auth = {}
$.post("https://api.dropbox.com/0/token", {
    email: encodeURI(email),
    password: encodeURI(password)
}, function (data) {
    auth = data
    upload()
})

function upload() {
    // Do magic here! `auth` is already configured; just pass its properties in the 'data' field to $.ajax() or $.post()
}

The "magic" mentioned in the comment is going to be a bit ugly, because you'll be encoding multipart/form-data HTTP headers for your POST. jQuery does not include any automagic encoding function. For recent browsers (Firefox 4, Chrome 5, Safari 5, ...) you can use some voodoo like the FormData API to do all the heavy lifting for you! In the case that you need to support older browsers, get ready for some banging-your-head-against-the-wall action!

multipart/form-data RFC: http://www.faqs.org/rfcs/rfc2388.html
An implementation, written in Python: http://code.activestate.com/recipes/146 ... form-data/

Once you have some encoded multipart/form-data crap, you can use $.ajax() to perform the actual call...

Code:
$.ajax("https://api-content.dropbox.com/0/files/dropbox/" + path, {
    type: "POST",
    data: formdata,
    contentType: "multipart/form-data; boundary=" + boundary
}

Where path is the path where the file will be uploaded, and formdata is the actual data that is going to be written (multipart/form-data encoded) ... and boundary is the MIME boundary (the Python code uses "----------ThIs_Is_tHe_bouNdaRY_$", but it can be anything, as long as it starts with LOTS OF HYPHENS. And the more obscure it is, the less chance it will have of causing false-positives when the server goes to scan for the data boundaries).


This biggest problem, by far, is that this will probably not work at all. To prevent XSRFs, browsers will not allow XMLHttpRequests to any domain that the JavaScript is not running on. That means your JS files must be served from both api.dropbox.com and api-content.dropbox.com. Fat chance! Using JSONP is a workaround for GET requests. As for POST requests ... well, I guess you could drop a form (with method=POST and multipart/form-data) into an iframe and manipulate it that way.

Honestly, that's pretty gross. Dropbox could fix all of that in one fell swoop just by sending the "Access-Control-Allow-Origin: *" header with all requests. :doh:

Oh, and see also: http://code.google.com/p/dropbox-js/

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group