 
           # Send it to my butt yo
           $.ajax(
-            type: "put"
-            crossDomain: true
-            contentType: "application/octet-stream"
-            dataType: "json"
-            url: "https://api-content.dropbox.com/1/files_put/sandbox/meta.seed"
-            data: JSON.stringify(result[0])
-            beforeSend: (xhr) ->
-              xhr.setRequestHeader 'Authorization', 'Bearer ' + Sync.oauth.access_token
+            Sync.generateRequest
+              request: "upload"
+              filename: "meta"
+              data: JSON.stringify(result[0])
           ).done (data) ->
             console.log("all done! Delete the queue")
             Sync.queue = {"Note": {}, "Notebook": {}}

                dbrequests[itemid].onsuccess = (e) =>
                  # Upload file to my butt.
                  $.ajax(
                    type: "put"
                    crossDomain: true
                    contentType: "application/octet-stream"
                    dataType: "text"
                    url: "https://api-content.dropbox.com/1/files_put/sandbox/" + itemid + ".seed"
                    data: e.target.result
                    beforeSend: (xhr) ->
                      xhr.setRequestHeader 'Authorization', 'Bearer ' + Sync.oauth.access_token
                  ).done (data) ->
                    deferred.resolve()

              when "download"
                # Download from my butt
                $.ajax(
                  type: "get"
                  crossDomain: true
                  dataType: "text"
                  url: "https://api-content.dropbox.com/1/files/sandbox/" + item[1] + ".seed"
                  beforeSend: (xhr) ->
                    xhr.setRequestHeader "Authorization", "Bearer " + Sync.oauth.access_token
                ).done (data) ->
                  # We now have to store the new data in the database.
                  trans = Sync.db.transaction(["notes"], "readwrite")

          console.log 'All files uploaded, uploading the meta file'

          $.ajax(
            Sync.generateRequest
              request: "upload"
              filename: "meta"
              data: Sync.exportData()
          ).done (data) ->
            console.log("all done! Delete the queue")
            Sync.queue = {"Note": {}, "Notebook": {}}
            Sync.saveQueue()

  generateRequest: (opts) ->
    if Sync.oauth.service is "dropbox"
      params =
        crossDomain: true
        dataType: opts.dataType || "json"
        beforeSend: (xhr) ->
          xhr.setRequestHeader "Authorization", "Bearer " + Sync.oauth.access_token

      if opts.request is "download"
        params.type = "get"
        params.url = "https://api-content.dropbox.com/1/files/sandbox/" + opts.filename + ".seed"

      else if opts.request is "upload"
        params.type = "put"
        params.contentType = opts.contentType || "application/octet-stream"
        params.url = "https://api-content.dropbox.com/1/files_put/sandbox/" + opts.filename + ".seed"
        data: opts.data

      else if opts.request is "destroy"
        params.type = "post"
        params.url = "https://api.dropbox.com/1/fileops/delete"
        params.data = {
          root: "sandbox"
          path: opts.filename + ".seed"
        }

      params # return

  connect: (fn) ->

